Hello can anyone help me please? its been 2 days anyway, so i just want to make a cashier restaurant order. i have a page with menu list and cart. my problem is when i klik "Beli"(Buy) button and enter amount of menu in the form the order details like menu name, price, quantity etc alway inserted in the first row in my order tables. I.E if i have 3 rows with id (1, 2, 3) the order details will just inserted in order tables with id 1. so i just want insert data appropriate with currently active order id. anyone know how to do it? sorry for my bad english and explanation
My Route
Route::get('/order/create', [OrderController::class, 'index'])->middleware('auth');
Route::post('/order/create/store', [OrderController::class, 'store_order_table'])->middleware('auth')->name('order_store');
Route::get('/order/edit/{id}', [OrderController::class, 'edit_order_table'])->middleware('auth')->name('edit_order');
Route::post('/order/details/{id}', [OrderController::class, 'create_order_details'])->middleware('auth');
Route::get('/order/list', [OrderController::class, 'get_order_list'])->middleware('auth');
My Controller
public function store_order_table(Request $request)
{
$order = Order::create([
'user_id' => Auth::user()->id,
'order_number' => $request->order_number,
'order_note' => $request->order_note
]);
return redirect()->route('edit_order', ['id' => $order->id]);
}
public function edit_order_table($id)
{
return view('cashier.edit_order', [
'menus' => Menu::all(),
'data' => Order::with('order_details')->where('id', $id)->first()
]);
}
public function create_order_details(Request $request, $id)
{
$menu = Menu::where('id', $id)->first();
$new_order = Order::where('user_id', Auth::user()->id)->where('is_paid', 0)->first();
$order_details = new OrderDetail;
$order_details->menu_id = $menu->id;
$order_details->menu_name = $menu->menu_name;
$order_details->order_id = $new_order->id;
$order_details->code = 1;
$order_details->quantity = $request->qty;
$order_details->one_unit_price = $menu->menu_price;
$order_details->total_price = $menu->menu_price * $request->qty;
$order_details->save();
return redirect()->route('edit_order', ['id' => $new_order->id]);
}
Aucun commentaire:
Enregistrer un commentaire