Все заказы получаю таким образом в админке:
public function index(): Renderable
{
$orders = Order::where('status', 1)->get();
return view('auth.orders.index', compact('orders'));
}
public function show(Order $order) {
return view('auth.orders.show', compact('order'));
}
Для обычного пользователя:
public function index(): Renderable
{
$orders = Auth::user()->orders()->where('status', 1)->get();
return view('auth.orders.index', compact('orders'));
}
public function show(Order $order)
{
if( !Auth::user()->orders->contains($order) ){
return redirect()->route('person.orders.index');
}
return view('auth.orders.show', compact('order'));
}
index() orders - Potentially polymorphic call. The code may be inoperable depending on the actual class instance passed as the argument.
Метод orders в user
public function orders()
{
return $this->hasMany(Order::class);
}
(В админке если что все выводится)