Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
104 lines
2.8 KiB
PHP
104 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\Pages;
|
|
|
|
use App\Filament\RelationManagers\ReviewsRelationManager;
|
|
use App\Filament\RelationManagers\RevisionsRelationManager;
|
|
use App\Filament\Resources\Pages\Pages\CreatePage;
|
|
use App\Filament\Resources\Pages\Pages\EditPage;
|
|
use App\Filament\Resources\Pages\Pages\ListPages;
|
|
use App\Filament\Resources\Pages\Schemas\PageForm;
|
|
use App\Filament\Resources\Pages\Tables\PagesTable;
|
|
use App\Models\Page;
|
|
use BackedEnum;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
use UnitEnum;
|
|
|
|
class PageResource extends Resource
|
|
{
|
|
protected static ?string $model = Page::class;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedDocumentText;
|
|
|
|
protected static ?int $navigationSort = 10;
|
|
|
|
public static function getModelLabel(): string
|
|
{
|
|
return __('panel.pages.label');
|
|
}
|
|
|
|
public static function getPluralModelLabel(): string
|
|
{
|
|
return __('panel.pages.plural');
|
|
}
|
|
|
|
public static function getNavigationGroup(): string|UnitEnum|null
|
|
{
|
|
return __('panel.groups.content');
|
|
}
|
|
|
|
public static function getRecordTitle(?Model $record): ?string
|
|
{
|
|
return $record?->getTranslation('title', app()->getLocale());
|
|
}
|
|
|
|
/**
|
|
* Global search looks inside the admin's current language only, so results
|
|
* read the way they expect rather than surfacing a stray English match.
|
|
*
|
|
* @return array<int, string>
|
|
*/
|
|
public static function getGloballySearchableAttributes(): array
|
|
{
|
|
return ['title->'.app()->getLocale()];
|
|
}
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return PageForm::configure($schema);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return PagesTable::configure($table);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
ReviewsRelationManager::class,
|
|
RevisionsRelationManager::class,
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListPages::route('/'),
|
|
'create' => CreatePage::route('/create'),
|
|
'edit' => EditPage::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function getRecordRouteBindingEloquentQuery(): Builder
|
|
{
|
|
return parent::getRecordRouteBindingEloquentQuery()
|
|
->withoutGlobalScopes([SoftDeletingScope::class]);
|
|
}
|
|
|
|
public static function getNavigationBadge(): ?string
|
|
{
|
|
$drafts = static::getModel()::query()->where('status', 'draft')->count();
|
|
|
|
return $drafts > 0 ? (string) $drafts : null;
|
|
}
|
|
}
|