has('admin_id')) { return redirect()->route('admin.login')->with('error', 'Please login first.'); } $allTimetables = Timetable::all(); $grid = []; foreach ($allTimetables as $item) { $grid[$item->time_slot][$item->day] = $item; } $days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']; $timeSlots = [ '08:30 - 10:30', '10:45 - 12:30', '12:30 - 01:30', // Lunch / Rest Time '01:30 - 03:30' ]; // Today's Day Name $today = Carbon::now()->format('l'); $todaySchedule = Timetable::where('day', $today)->get(); return view('admin.admintimetable', compact('allTimetables', 'days', 'timeSlots', 'grid', 'todaySchedule', 'today')); } public function store(Request $request) { $request->validate([ 'time_slot' => 'required|string', 'day' => 'required|string', 'subject_name' => 'required|string|max:255', 'type' => 'required|string', ]); Timetable::updateOrCreate( [ 'day' => $request->day, 'time_slot' => $request->time_slot, ], [ 'subject_name' => $request->subject_name, 'type' => $request->type, ] ); return redirect()->back()->with('success', 'Timetable saved successfully!'); } // Delete Single Slot public function destroy($id) { $timetable = Timetable::findOrFail($id); $timetable->delete(); return redirect()->back()->with('success', 'Timetable slot cleared successfully!'); } }