/
ghx
/
TicketFlow
Обзор
Документация
Войти
/
ghx
/
TicketFlow
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
app/Http/Controllers/SessionSeatController.php
71 строка
2 KB
osnov
.
26 июн 2026, 11:56
26 июн 2026, 11:56
dc2de34
Код
Авторство
О чём код?
<?php namespace App\Http\Controllers; use App\Models\Session; use App\Models\Ticket; use App\Services\HallSeatService; class SessionSeatController extends Controller { public function show(Session $session, HallSeatService $seatService) { $session->load(['movie', 'hall']); if ($session->hall->seats()->count() === 0) { $seatService->syncSeats($session->hall); } $occupiedIds = Ticket::query() ->where('showtime_id', $session->id) ->whereIn('status', ['reserved', 'paid']) ->pluck('seat_id') ->all(); $seats = $session->hall->seats() ->orderBy('row') ->orderBy('seat_number') ->get() ->map(fn ($seat) => [ 'id' => $seat->id, 'row' => $seat->row, 'seat_number' => $seat->seat_number, 'occupied' => in_array($seat->id, $occupiedIds, true), ]); $relatedSessions = Session::with('hall') ->where('movie_id', $session->movie_id) ->whereDate('start_time', $session->start_time->toDateString()) ->where('start_time', '>=', now()) ->orderBy('start_time') ->get() ->map(fn ($item) => [ 'id' => $item->id, 'hall_id' => $item->hall_id, 'hall' => $item->hall->name, 'start_time' => $item->start_time->format('H:i'), 'price' => (float) $item->price, 'is_current' => $item->id === $session->id, ]); return response()->json([ 'session' => [ 'id' => $session->id, 'movie_id' => $session->movie_id, 'hall_id' => $session->hall_id, 'start_time' => $session->start_time->format('d.m.Y H:i'), 'price' => (float) $session->price, 'movie' => $session->movie->title, 'hall' => $session->hall->name, ], 'hall' => [ 'id' => $session->hall->id, 'name' => $session->hall->name, 'rows' => $session->hall->rows, 'seats_per_row' => $session->hall->seats_per_row, ], 'seats' => $seats, 'related_sessions' => $relatedSessions, ]); } }