Я создаю небольшой интернет-магазин, где пользователи могут создавать заказы, а продавцы могут видеть заказы. Я определил отношения, но связанные функции являются нулевыми. Вот так выглядят мои таблицы в phpmyAdmin https://imgur.com/a/C2PSmFt
Вот как я определил отношения в моих моделях.
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');
}
Это моя функция в контроллере
$orders = Auth::user()->sellerOrders()->with('productInfo','orderInfo')->get();
Когда я dd($orders)
, это то, что я получаю
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 [▶]
}
]
}
Как мне показать productInfo
и orderInfo
? Ваша помощь очень ценится.