32 lines
1016 B
PHP
32 lines
1016 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Domain\Reservations\Models\Reservation;
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class GlobalCalendarController extends Controller
|
|
{
|
|
public function __invoke(Request $request): Response
|
|
{
|
|
$filters = $request->validate(['month' => ['nullable', 'date_format:Y-m']]);
|
|
$month = isset($filters['month'])
|
|
? CarbonImmutable::createFromFormat('!Y-m', $filters['month'])
|
|
: now()->startOfMonth();
|
|
|
|
return Inertia::render('reservations/calendar', [
|
|
'scope' => 'global',
|
|
'month' => $month->format('Y-m'),
|
|
'reservations' => Reservation::query()
|
|
->with(['requester:id,name,department', 'items.asset:id,name,asset_tag'])
|
|
->where('starts_at', '<', $month->addMonth())
|
|
->where('ends_at', '>', $month)
|
|
->orderBy('starts_at')
|
|
->get(),
|
|
]);
|
|
}
|
|
}
|