2026-05-20 18:25:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2026-05-27 21:24:38 +02:00
|
|
|
use App\Helpers\EntryHelpers;
|
2026-05-20 18:25:15 +02:00
|
|
|
use App\Models\Entry;
|
2026-06-02 20:54:10 +02:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2026-05-20 18:25:15 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
|
|
class EntryController extends Controller
|
|
|
|
|
{
|
|
|
|
|
|
2026-06-02 20:54:10 +02:00
|
|
|
private const SECTION_TYPES = ['translations', 'romhacks', 'homebrew', 'utilities', 'documents', 'lua-scripts', 'tutorials'];
|
2026-05-20 18:25:15 +02:00
|
|
|
|
|
|
|
|
public function index(): View
|
|
|
|
|
{
|
2026-05-24 11:47:20 +02:00
|
|
|
return view('entries.index');
|
2026-05-20 18:25:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function show(string $section, Entry $entry): View
|
|
|
|
|
{
|
2026-06-02 20:54:10 +02:00
|
|
|
if (!in_array($section, self::SECTION_TYPES))
|
2026-05-20 18:25:15 +02:00
|
|
|
abort(404);
|
|
|
|
|
|
2026-06-02 20:54:10 +02:00
|
|
|
if ($entry->type !== $section)
|
2026-05-20 18:25:15 +02:00
|
|
|
abort(404);
|
|
|
|
|
|
2026-06-02 20:54:10 +02:00
|
|
|
Gate::authorize('viewAny', $entry);
|
|
|
|
|
|
|
|
|
|
// Permissions.
|
|
|
|
|
$entryPolicy = match ($entry->state) {
|
|
|
|
|
'pending' => 'viewPending',
|
|
|
|
|
'draft' => 'viewDraft',
|
|
|
|
|
'rejected' => 'viewRejected',
|
|
|
|
|
'hidden' => 'viewHidden',
|
|
|
|
|
'locked' => 'viewLocked',
|
|
|
|
|
'published' => null,
|
|
|
|
|
'default' => null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if ($entryPolicy)
|
|
|
|
|
Gate::authorize($entryPolicy, $entry);
|
|
|
|
|
|
|
|
|
|
$comments = EntryHelpers::getLatestComments($entry);
|
2026-05-27 21:24:38 +02:00
|
|
|
|
2026-06-02 20:54:10 +02:00
|
|
|
return view('entries.show', compact('entry', 'section', 'comments'));
|
2026-05-20 18:25:15 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|