我目前正在学习Laravel制作购物车系统,我正在尝试创建一个“实时”仪表板页面,显示新订单,因为它们是在数据库中创建的,而无需刷新页面。我已经搜索了答案,但似乎没有工作,我猜这是一个简单的获取请求?
路线:
Route::get('/staff', [
'uses' => 'StaffController@getIndex',
'as' => 'staff',
'middleware' => 'roles',
'roles' => ['Manager', 'Pizzaiolo']
]);
控制器功能:
public function getIndex() {
$orders_open = Order::where('order_complete', 0)->get();
$orders_open->transform(function($order, $key) {
$order->cart = unserialize($order->cart);
return $order;
});
$orders_closed = Order::where('order_complete', 1)
->orderBy('id', 'desc')
->get();
$orders_closed->transform(function($order, $key) {
$order->cart = unserialize($order->cart);
return $order;
});
return view('staff.dashboard', ['orders_open' => $orders_open, 'orders_closed' => $orders_closed]);
}
非常感谢任何帮助:)