I'm trying to query buyer orders from database to their profile(dashboard), so when a buyer place order he should see the order information in his dashboard.
My code isn't working well, how do I fix this.
Controller
public function myOrders(User $user)
{
$orders=Order::where('buyer_id',$user->id)->get();
return view('myOrders', compact('user','orders'));
//dd($orders);
}
Blade view
@foreach($orders as $sell)
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<a href="">View Order Details</a>
</td>
</tr>
@endforeach
User.php
public function orders()
{
return $this->hasManyThrough(Order::class, Products_model::class, 'buyer_id', 'seller_id', 'product_id');
}
public function orderFromBuyers()
{
return $this->hasManyThrough(OrderProduct::class, Products_model::class, 'buyer_id', 'product_id');
}
public function orderFromSellers()
{
return $this->hasManyThrough(OrderProduct::class, Products_model::class, 'seller_id', 'product_id');
}
OrderProduct.php
public function buyer()
{
return $this->belongsTo(User::class, 'id', 'buyer_id');
}
public function seller()
{
return $this->belongsTo(User::class, 'id', 'seller_id');
}
public function order()
{
return $this->belongsTo(Order::class);
}
Any help will be appreciated
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire