I'm stuck trying to show orders that belong to a seller of the product. Right now when a user place an order that has multiple products from different sellers, the order appear to all sellers. for example product 1,2,3 sold by a,b,c respectively, if a customer orders 1,2 at once both a,b see the order instead of product 1 to go to seller a and 2 to b.
How can i filter and show only the order that belong to the seller of the product.
here is how my relationships are defined in models
User.php
public function orderInfo()
{
return $this->belongsToMany(Order::class,'order_product','seller_id');
}
Order.php
public function item()
{
return $this->belongsToMany('App\Product')->withPivot('quantity','total','Subtotal');
}
in Product.php and Order_Product.php there is no relationship defined.
And this is my controller
// Seller Orders
public function viewOrders(User $user)
{
$orders = Auth::user()->orderInfo()->with('item')->get();
//dd($orders);
return view('orders')->with('orders', $orders);
}
Here is how my tables looks like https://imgur.com/a/C2PSmFt
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire