43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
// app/Http/Controllers/Admin/CalendarController.php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\CalendarService;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CalendarController extends Controller
|
|
{
|
|
public function index(\Illuminate\Http\Request $request)
|
|
{
|
|
// Make sure you also have at the top of the file:
|
|
// use App\Models\Slot;
|
|
// use Carbon\Carbon;
|
|
|
|
$now = \Carbon\Carbon::now('Europe/London');
|
|
|
|
// Default week, flip to next after Fri 15:00
|
|
$start = $now->copy()->startOfWeek(\Carbon\Carbon::MONDAY);
|
|
$fridayCutoff = $start->copy()->addDays(4)->setTime(15, 0);
|
|
if ($now->greaterThanOrEqualTo($fridayCutoff)) {
|
|
$start->addWeek();
|
|
}
|
|
|
|
// Week navigation
|
|
$weekOffset = (int) $request->query('week', 0);
|
|
if ($weekOffset !== 0) {
|
|
$start->addWeeks($weekOffset);
|
|
}
|
|
$end = $start->copy()->addDays(6);
|
|
|
|
// 👉 Load slots with bookings for the visible week
|
|
$slots = \App\Models\Slot::with(['bookings' => function ($q) use ($start, $end) {
|
|
$q->whereBetween('date', [$start->toDateString(), $end->toDateString()]);
|
|
}])->get();
|
|
|
|
// 👉 Pass $slots (and the other vars) to the view
|
|
return view('calendar.index', compact('start', 'end', 'weekOffset', 'slots', 'now'));
|
|
}
|
|
} |