Answer the question
In order to leave comments, you need to log in
Correctly compose relations in Laravel?
There is a model
Product
{
return $this->hasOne(ProductDescription::class,'product_id','product_id')->where('language_id','=', 1);
}
Order
public function products()
{
return $this->hasMany(OrderProduct::class,'order_id');
}
OrderProduct
public function description()
{
return $this->hasOne(ProductDescription::class,'product_id','product_id')->where('language_id','=', 1);
}
public function product()
{
return $this->belongsTo(Product::class,'product_id');
}
$orders = Order::select(
'orders.*',
)
->with(['products' => function($query){
$query->with(['description','product']);
}])
->where('user_id','=', Auth::user()->id)
->paginate(30);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question