42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Timetable;
|
|
use Carbon\Carbon;
|
|
|
|
class TimetableController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$studentLogId = session('student_log_id') ?? session('student_id');
|
|
|
|
if (!$studentLogId) {
|
|
return redirect('/signin')->with('error', 'Please login first!');
|
|
}
|
|
|
|
|
|
$rawTimetables = Timetable::all();
|
|
|
|
$schedule = [];
|
|
$timeSlots = [];
|
|
|
|
foreach ($rawTimetables as $item) {
|
|
if (!in_array($item->time_slot, $timeSlots)) {
|
|
$timeSlots[] = $item->time_slot;
|
|
}
|
|
$schedule[$item->time_slot][$item->day] = $item;
|
|
}
|
|
|
|
|
|
$todayName = Carbon::now()->format('l');
|
|
$todaySchedule = Timetable::where('day', $todayName)
|
|
->where('type', '!=', 'Break')
|
|
->get();
|
|
|
|
$days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
|
|
|
|
return view('timetable', compact('schedule', 'timeSlots', 'days', 'todaySchedule', 'todayName'));
|
|
}
|
|
} |