mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
278 lines
7.2 KiB
PHP
278 lines
7.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\Admin;
|
|
|
|
use App\Filament\Components\Columns\TextColumn;
|
|
use App\Filament\Components\Infolist\TextEntry;
|
|
use App\Filament\Resources\BaseResource;
|
|
use App\Filament\Resources\Admin\Announcement\Pages\CreateAnnouncement;
|
|
use App\Filament\Resources\Admin\Announcement\Pages\EditAnnouncement;
|
|
use App\Filament\Resources\Admin\Announcement\Pages\ListAnnouncements;
|
|
use App\Filament\Resources\Admin\Announcement\Pages\ViewAnnouncement;
|
|
use App\Models\Admin\Announcement as AnnouncementModel;
|
|
use Filament\Forms\Components\MarkdownEditor;
|
|
use Filament\Forms\Form;
|
|
use Filament\Infolists\Components\Section;
|
|
use Filament\Infolists\Infolist;
|
|
use Filament\Resources\RelationManagers\RelationGroup;
|
|
use Filament\Tables\Table;
|
|
|
|
/**
|
|
* Class Announcement.
|
|
*/
|
|
class Announcement extends BaseResource
|
|
{
|
|
/**
|
|
* The model the resource corresponds to.
|
|
*
|
|
* @var string|null
|
|
*/
|
|
protected static ?string $model = AnnouncementModel::class;
|
|
|
|
/**
|
|
* Get the displayable singular label of the resource.
|
|
*
|
|
* @return string
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getLabel(): string
|
|
{
|
|
return __('filament.resources.singularLabel.announcement');
|
|
}
|
|
|
|
/**
|
|
* Get the displayable label of the resource.
|
|
*
|
|
* @return string
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getPluralLabel(): string
|
|
{
|
|
return __('filament.resources.label.announcements');
|
|
}
|
|
|
|
/**
|
|
* The logical group associated with the resource.
|
|
*
|
|
* @return string
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getNavigationGroup(): string
|
|
{
|
|
return __('filament.resources.group.admin');
|
|
}
|
|
|
|
/**
|
|
* The icon displayed to the resource.
|
|
*
|
|
* @return string
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getNavigationIcon(): string
|
|
{
|
|
return __('filament.resources.icon.announcements');
|
|
}
|
|
|
|
/**
|
|
* Get the slug (URI key) for the resource.
|
|
*
|
|
* @return string
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getRecordSlug(): string
|
|
{
|
|
return 'announcements';
|
|
}
|
|
|
|
/**
|
|
* Get the route key for the resource.
|
|
*
|
|
* @return string
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getRecordRouteKeyName(): string
|
|
{
|
|
return AnnouncementModel::ATTRIBUTE_ID;
|
|
}
|
|
|
|
/**
|
|
* The form to the actions.
|
|
*
|
|
* @param Form $form
|
|
* @return Form
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
MarkdownEditor::make(AnnouncementModel::ATTRIBUTE_CONTENT)
|
|
->label(__('filament.fields.announcement.content'))
|
|
->required()
|
|
->rules(['required', 'max:65535'])
|
|
->maxLength(65535),
|
|
])
|
|
->columns(1);
|
|
}
|
|
|
|
/**
|
|
* The index page of the resource.
|
|
*
|
|
* @param Table $table
|
|
* @return Table
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function table(Table $table): Table
|
|
{
|
|
return parent::table($table)
|
|
->columns([
|
|
TextColumn::make(AnnouncementModel::ATTRIBUTE_ID)
|
|
->label(__('filament.fields.base.id'))
|
|
->sortable(),
|
|
|
|
TextColumn::make(AnnouncementModel::ATTRIBUTE_CONTENT)
|
|
->label(__('filament.fields.announcement.content'))
|
|
->sortable()
|
|
->searchable()
|
|
->copyableWithMessage(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the infolist available for the resource.
|
|
*
|
|
* @param Infolist $infolist
|
|
* @return Infolist
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function infolist(Infolist $infolist): Infolist
|
|
{
|
|
return $infolist
|
|
->schema([
|
|
Section::make(static::getRecordTitle($infolist->getRecord()))
|
|
->schema([
|
|
TextEntry::make(AnnouncementModel::ATTRIBUTE_ID)
|
|
->label(__('filament.fields.base.id')),
|
|
|
|
TextEntry::make(AnnouncementModel::ATTRIBUTE_CONTENT)
|
|
->label(__('filament.fields.announcement.content'))
|
|
->markdown()
|
|
->columnSpanFull()
|
|
->copyableWithMessage(),
|
|
])
|
|
->columns(3),
|
|
|
|
Section::make(__('filament.fields.base.timestamps'))
|
|
->schema(parent::timestamps())
|
|
->columns(3),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the relationships available for the resource.
|
|
*
|
|
* @return array
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
RelationGroup::make(static::getLabel(),
|
|
array_merge(
|
|
[],
|
|
parent::getBaseRelations(),
|
|
)
|
|
),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the filters available for the resource.
|
|
*
|
|
* @return array
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getFilters(): array
|
|
{
|
|
return array_merge(
|
|
parent::getFilters(),
|
|
[]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the actions available for the resource.
|
|
*
|
|
* @return array
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getActions(): array
|
|
{
|
|
return array_merge(
|
|
parent::getActions(),
|
|
[],
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the bulk actions available for the resource.
|
|
*
|
|
* @return array
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getBulkActions(): array
|
|
{
|
|
return array_merge(
|
|
parent::getBulkActions(),
|
|
[],
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the header actions available for the resource.
|
|
*
|
|
* @return array
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getHeaderActions(): array
|
|
{
|
|
return array_merge(
|
|
parent::getHeaderActions(),
|
|
[],
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the pages available for the resource.
|
|
*
|
|
* @return array
|
|
*
|
|
* @noinspection PhpMissingParentCallCommonInspection
|
|
*/
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListAnnouncements::route('/'),
|
|
'create' => CreateAnnouncement::route('/create'),
|
|
'view' => ViewAnnouncement::route('/{record:announcement_id}'),
|
|
'edit' => EditAnnouncement::route('/{record:announcement_id}/edit'),
|
|
];
|
|
}
|
|
}
|