- Upgrade Filament framework from v3 to v4 - Update all Filament resources and pages for v4 compatibility - Fix test suite to maintain 100% pass rate (321 tests passing) - Add visibility condition for ticket close action (only when not closed) - Update dependencies and build assets for new Filament version - Maintain backward compatibility while leveraging v4 improvements
155 lines
5.5 KiB
PHP
155 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Schemas\Components\Utilities\Set;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use App\Filament\Resources\PageResource\Pages\ListPages;
|
|
use App\Filament\Resources\PageResource\Pages\CreatePage;
|
|
use App\Filament\Resources\PageResource\Pages\EditPage;
|
|
use App\Filament\Resources\PageResource\Pages;
|
|
use App\Filament\Resources\PageResource\RelationManagers;
|
|
use App\Models\Page;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Components\FileUpload;
|
|
use Filament\Forms\Components\KeyValue;
|
|
use Filament\Forms\Components\Repeater;
|
|
use Filament\Forms\Components\RichEditor;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Illuminate\Support\Str;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
use Symfony\Contracts\Service\Attribute\Required;
|
|
|
|
class PageResource extends Resource
|
|
{
|
|
protected static ?string $model = Page::class;
|
|
|
|
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-document';
|
|
|
|
protected static string | \UnitEnum | null $navigationGroup = 'Content';
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
$pages = Page::Pluck('title', 'id')->toArray();
|
|
|
|
return $schema
|
|
->components([
|
|
|
|
Section::make('Page Information')
|
|
->description('Add a new page')
|
|
->schema([
|
|
TextInput::make('title')->label('Page Title')
|
|
->required()
|
|
->live(1)
|
|
->columnSpanFull()
|
|
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))),
|
|
TextInput::make('slug')->required()->columnSpan(3),
|
|
Select::make('is_published')
|
|
->options([
|
|
0 => 'Draft',
|
|
1 => 'Published'
|
|
])
|
|
->default(1)
|
|
->required()
|
|
->searchable()
|
|
->label('Status')
|
|
->columnSpan(1),
|
|
RichEditor::make('content')->label('Page Content')->required()->columnSpanFull(),
|
|
FileUpload::make('page_image')
|
|
->label('Custom Image (Optional)')
|
|
->directory('media/pages')
|
|
->columnSpanFull()
|
|
->preserveFilenames()
|
|
->image()
|
|
->maxSize(2048),
|
|
])
|
|
->columns(4),
|
|
|
|
Section::make('Customize Page')
|
|
->description('Modifiy Page SEO and Meta Information')
|
|
->schema([
|
|
KeyValue::make('meta')
|
|
->label('Meta (Optional)')
|
|
->keyPlaceholder('Name')
|
|
->valuePlaceholder('Content')
|
|
->reorderable(),
|
|
Select::make('parent')->options($pages)->label('Parents (Optional)'),
|
|
Textarea::make('custom_header')->rows(6)->label('Custom Header (Optional)'),
|
|
]),
|
|
|
|
|
|
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('title')->searchable(),
|
|
TextColumn::make('slug'),
|
|
IconColumn::make('is_published')->label('Published')->boolean(),
|
|
TextColumn::make('created_at')
|
|
->label('Created At'),
|
|
])
|
|
->defaultSort('created_at', 'desc')
|
|
->filters([
|
|
SelectFilter::make('is_published')
|
|
->label('Status')
|
|
->options([
|
|
0 => 'Draft',
|
|
1 => 'Published',
|
|
]),
|
|
])
|
|
->recordActions([
|
|
ViewAction::make(),
|
|
EditAction::make(),
|
|
DeleteAction::make(),
|
|
Action::make('togglePublished')
|
|
->label('Toggle Published')
|
|
->icon('heroicon-o-eye')
|
|
->action(function (Page $record) {
|
|
$record->update(['is_published' => !$record->is_published]);
|
|
}),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListPages::route('/'),
|
|
'create' => CreatePage::route('/create'),
|
|
'edit' => EditPage::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|