I am currently learning Laravel making a cart system, I am trying to make a "live" dashboard page that displays new orders as they are created in the database without someone having to refresh the page. I have searched for answers but none seem to work, I'm guessing this is a simple get request?
Route:
Route::get('/staff', [
'uses' => 'StaffController@getIndex',
'as' => 'staff',
'middleware' => 'roles',
'roles' => ['Manager', 'Pizzaiolo']
]);
Controller function:
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]);
}
Any help would be much appreciated :)
via Jitarrias