jeudi 4 juillet 2019

How to exclude product in the order by different sellers in laravel?

I'm trying to show orders that belong to a certain seller when a customer place an order. The problem comes when a customer buys multiple products at once from different sellers.The order(including other products in cart) goes to the seller whose product is last in cart.

if the order is only one product everything seems to work. Here is how my query looks like in controller.

// Seller Orders 
public function viewOrders(User $user)
{

$orders = Auth::user()->Order()->with('products')->orderBy('id', 'DESC')->paginate(2);  
 return view('orders')->with('orders', $orders);
 }

Here is my user.php

public function Order()
{
     return $this->hasMany(Order::class, 'seller_id');
}

Here is Order.php

public function user()
{
    return $this->belongsTo('App\User', 'seller_id');
}

public function products()
{
    return $this->belongsToMany('App\Product')->withPivot('quantity');
}

Here is how my tables looks like https://imgur.com/a/2uF5iuS Any help would be appreciated.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Jbralh
via IFTTT

Aucun commentaire:

Enregistrer un commentaire