に多くの要素を取得することは次である:は私の問題:-)私の悪い英語のために、私は申し訳ありませんが、多くのlaravel 5
私は多くの
クラス順序
class Order extends Model
{
public function user(){
return $this->belongsTo('App\User');
}
public function products(){
return $this->belongsToMany('App\Product', 'order_product')
->withPivot('order_id', 'product_quantity', 'subtotal');
}
public function pay(){
$this->hasOne('App\Pay');
}
public function status(){
$this->hasOne('App\Statu');
}
}
の多くと、次の関係を持っています
クラスの製品
class Product extends Model
{
public function images(){
return $this->hasMany('App\Image');
}
public function carts(){
return $this->belongsToMany('App\Cart', 'cart_product')
->withPivot('cart_id','quantity');
}
public function orders(){
return $this->belongsToMany('App\Order', 'order_product')
->withPivot('product_id', 'product_quantity', 'subtotal');
}
}
クラスユーザー
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'address', 'telephone', 'mobile', 'rif', 'ci',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function cart(){
return $this->hasOne('App\Cart');
}
public function orders(){
return $this->hasMany('App\Order');
}
}
クラスペイ
class Pay extends Model
{
public function order(){
$this->belongsTo('App\Order');
}
}
クラス彫像
class Statu extends Model
{
protected $table = 'status';
public function order(){
$this->belongsTo('App\Order');
}
}
コントローラのメソッドは次のとおりです。
public function index(){
$orders = User::find(Auth::user()->id)->orders;
return view('order.list', compact('orders'));
}
エラーが表示で存在している(私が表示したいテーブルの識別子を表す名前STATU)
<tbody>
@foreach($orders as $order)
<tr>
<th class="row">{{ $order->id }}</th>
<td>{{ $order->date }}</td>
<td>{{ $order->status_id }}</td><-- ***HERE***
<td>{{ $order->pay_id }}</td>
<td>{{ $order->total_product }}</td>
<td>{{ $order->mount }}</td>
<td><a class="btn btn-primary btn-xs" href="detail/{{ $order->id }}">detalles</a></td>
</tr>
@endforeach
</tbody>
エラー
ビューで正しく今
とできる。 – Tibrogargan
@manniLに感謝します。$ order-> status_idには現在のエラーはありません。しかし、持っていたいのは、STATUテーブルのidを表す名前です。私はそれを得ることはありません – UclidesGil