I'm creating a small webshop where users can create orders and sellers can see the orders. I have defined relationships but the related functions are null. This is how my tables looks like in phpmyAdmin https://imgur.com/a/C2PSmFt
this is how i have defined relationships in my models.
User.php
public function sellerOrders()
{
return $this->hasMany(Order::class);
}
Order.php
public function user()
{
return $this->belongsTo('App\User', 'seller_id');
}
public function products()
{
return $this->belongsToMany('App\Product')->withPivot('quantity','total','Subtotal');
}
public function productInfo()
{
return $this->belongsTo('App\Product');
}
public function orderInfo()
{
return $this->belongsTo(OrderProduct::class, 'seller_id');
}
This is my function in controller
$orders = Auth::user()->sellerOrders()->with('productInfo','orderInfo')->get();
when i dd($orders), this is what i get
Collection {#305 ▼
#items: array:1 [▼
0 => Order {#286 ▼
#table: "orders"
#fillable: array:5 [▶]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:8 [▼
"id" => 9
"user_id" => 1
"shipping_email" => "878888"
"shipping_name" => "hattta"
"shipping_city" => "kljjdjd"
"shipped" => 0
"created_at" => "2019-07-05 01:33:58"
"updated_at" => "2019-07-05 01:33:58"
]
#original: array:8 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:2 [▼
"productInfo" => null
"orderInfo" => null
]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
]
}
How can i show productInfo and orderInfo? Your help is really appreciated.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2YAhTZg
via IFTTT
Aucun commentaire:
Enregistrer un commentaire