I'm trying to display orders of a buyer and product details like name, price,total etc. After a buyer logged in should be able to see his order history and the product he ordered . So far when I dd($orders) I get order details but not product details,this is what I get->(https://imgur.com/a/kH0Lara). So how do I get product details too.
Here is my models and functions
Buyer Function
public function myOrders()
{
$orders = auth()->user()->allOrderFromBuyers()->with('orders')->get();
dd($orders);
return view('myOrders')->with(compact('orders'));
}
User.php
public function products()
{
return $this->hasMany(Products_model::class);
}
public function orders()
{
return $this->hasMany(Order::class, Products_model::class, 'buyer_id', 'seller_id', 'product_id');
}
public function allOrderFromBuyers()
{
return $this->hasMany(OrderProduct::class, 'buyer_id');
}
Oder.php
public function user()
{
return $this->belongsTo('App\User');
}
public function products()
{
return $this->belongsToMany(Products_model::class, 'order_product');//gggg
}
public function orders(){
return $this->hasMany('App\OrderProduct', 'order_id');
}
Products_model.php
protected $fillable= ['seller_id','pro_name','pro_price','pro_info','image','stock','category_id'];
public function orders()
{
return $this->belongsToMany('App\Order', 'order_product');
}
OrderProduct.php
public function products()
{
return $this->belongsTo('App\Products_model');
}
public function buyer()
{
return $this->belongsTo(User::class, 'id', 'buyer_id');
}
public function orders()
{
return $this->belongsTo(Order::class);
}
I have tried my best but am stuck, any help will be appreciated.
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2XZpZu7
via IFTTT
Aucun commentaire:
Enregistrer un commentaire