I have 3 models named "User","Order","Orders_products". The relations are following:
Here are the model's code
User Model
public function order(){
return $this->hasMany('App\Order');
}
Order Model
public function order_product(){
return $this-> hasMany('App\Orders_product');
}
public function user(){
return $this-> belongsTo('App\User');
}
Orders_products Model
public function order(){
return $this->belongsTo('App\Order');
}
An user could have multiple orders and all orders could have multiple ordered products. How can i get a particular users all orders along with the ordered products.
$Order = Order::with('order_product')->where(['user_id'=>$id])->get();
where $id
is the user_id