input('status', 'all'); if ($status === 'all') { $orders = Order::orderBy('created_at', 'desc')->get(); } else { $orders = Order::where('order_status', $status)->orderBy('created_at', 'desc')->get(); } return view('admin.orders.index', ['orders' => $orders, 'status' => $status]); } /** * Show the form for creating a new resource. */ public function create() { // } /** * Store a newly created resource in storage. */ public function store(Request $request) { // } /** * Display the specified resource. */ public function show(string $id) { // $order = Order::find($id); if (!$order) { return redirect()->route('orders.index')->with('error', 'Order not found'); } return view('admin.orders.show', ['order' => $order]); } /** * Show the form for editing the specified resource. */ public function edit(string $id) { // } /** * Update the specified resource in storage. */ public function update(Request $request, string $id) { // } /** * Remove the specified resource from storage. */ public function destroy(string $id) { // } public function markDelivered($id) { $order = Order::find($id); if (!$order) { return redirect()->route('orders.index')->with('error', 'Order not found'); } if ($order->order_status === 'Pending') { $order->update(['order_status' => 'Delivered', 'payment_status' => 'Paid']); return redirect()->route('orders.index')->with('success', 'Order marked as delivered and paid'); } else { return redirect()->route('orders.index')->with('error', 'Order is not in the Pending status'); } } }