Files
2026-03-19 19:40:49 +02:00

46 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Event;
use App\Models\Issue;
use App\Models\Project;
use Illuminate\Http\Request;
use Illuminate\View\View;
class EventController extends Controller
{
public function show(Request $request, Project $project, Issue $issue, Event $event): View
{
$this->authorizeProject($request, $project);
abort_unless($issue->project_id === $project->id, 404);
abort_unless($event->issue_id === $issue->id, 404);
$previousEvent = Event::where('issue_id', $issue->id)
->where('timestamp', '<', $event->timestamp)
->orderByDesc('timestamp')
->first();
$nextEvent = Event::where('issue_id', $issue->id)
->where('timestamp', '>', $event->timestamp)
->orderBy('timestamp')
->first();
return view('events.show', [
'project' => $project,
'issue' => $issue,
'event' => $event,
'previousEvent' => $previousEvent,
'nextEvent' => $nextEvent,
]);
}
private function authorizeProject(Request $request, Project $project): void
{
abort_unless(
$request->user()->projects()->where('projects.id', $project->id)->exists(),
403,
);
}
}