Club System
This commit is contained in:
@@ -4,31 +4,47 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Helpers\EntryHelpers;
|
||||
use App\Models\Entry;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EntryController extends Controller
|
||||
{
|
||||
|
||||
private const SECTION_TYPES = [ 'translations', 'romhacks', 'homebrew', 'utilities', 'documents', 'lua-scripts', 'tutorials' ];
|
||||
private const SECTION_TYPES = ['translations', 'romhacks', 'homebrew', 'utilities', 'documents', 'lua-scripts', 'tutorials'];
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
|
||||
return view('entries.index');
|
||||
}
|
||||
|
||||
public function show(string $section, Entry $entry): View
|
||||
{
|
||||
if( ! in_array($section, self::SECTION_TYPES) )
|
||||
if (!in_array($section, self::SECTION_TYPES))
|
||||
abort(404);
|
||||
|
||||
if( $entry->type !== $section )
|
||||
if ($entry->type !== $section)
|
||||
abort(404);
|
||||
|
||||
$comments = EntryHelpers::getLatestComments( $entry );
|
||||
Gate::authorize('viewAny', $entry);
|
||||
|
||||
return view('entries.show', compact('entry', 'section', 'comments' ) );
|
||||
// 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);
|
||||
|
||||
return view('entries.show', compact('entry', 'section', 'comments'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user