mirror of
https://github.com/pacnpal/thrillwiki_laravel.git
synced 2025-12-20 09:11:10 -05:00
feat: add middleware for cookie encryption, CSRF verification, string trimming, and maintenance request prevention; implement Designer resource management with CRUD pages and permissions
This commit is contained in:
125
app/Filament/Resources/DesignerResource.php
Normal file
125
app/Filament/Resources/DesignerResource.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\DesignerResource\Pages;
|
||||
use App\Filament\Resources\DesignerResource\RelationManagers;
|
||||
use App\Models\Designer;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class DesignerResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Designer::class;
|
||||
protected static ?string $navigationIcon = 'heroicon-o-building-office';
|
||||
protected static ?string $navigationGroup = 'Company Management';
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Section::make('Basic Information')
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->live(onBlur: true)
|
||||
->afterStateUpdated(fn ($state, Forms\Set $set) =>
|
||||
$set('slug', str($state)->slug())),
|
||||
Forms\Components\TextInput::make('slug')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->unique(ignoreRecord: true),
|
||||
Forms\Components\TextInput::make('headquarters')
|
||||
->maxLength(255),
|
||||
Forms\Components\DatePicker::make('founded_date')
|
||||
->label('Founded Date')
|
||||
->format('Y-m-d'),
|
||||
])->columns(2),
|
||||
|
||||
Forms\Components\Section::make('Additional Details')
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('website')
|
||||
->url()
|
||||
->prefix('https://')
|
||||
->maxLength(255),
|
||||
Forms\Components\RichEditor::make('description')
|
||||
->columnSpanFull()
|
||||
->toolbarButtons([
|
||||
'bold',
|
||||
'italic',
|
||||
'link',
|
||||
'bulletList',
|
||||
'orderedList',
|
||||
'h2',
|
||||
'h3',
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('headquarters')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('founded_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('rides_count')
|
||||
->counts('rides')
|
||||
->label('Rides')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('website')
|
||||
->searchable()
|
||||
->url(fn ($state) => str($state)->start('https://')),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\Filter::make('has_rides')
|
||||
->query(fn (Builder $query) => $query->has('rides'))
|
||||
->label('Has Rides'),
|
||||
Tables\Filters\Filter::make('no_rides')
|
||||
->query(fn (Builder $query) => $query->doesntHave('rides'))
|
||||
->label('No Rides'),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\ViewAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\RidesRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListDesigners::route('/'),
|
||||
'create' => Pages\CreateDesigner::route('/create'),
|
||||
'edit' => Pages\EditDesigner::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DesignerResource\Pages;
|
||||
|
||||
use App\Filament\Resources\DesignerResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateDesigner extends CreateRecord
|
||||
{
|
||||
protected static string $resource = DesignerResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DesignerResource\Pages;
|
||||
|
||||
use App\Filament\Resources\DesignerResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditDesigner extends EditRecord
|
||||
{
|
||||
protected static string $resource = DesignerResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DesignerResource\Pages;
|
||||
|
||||
use App\Filament\Resources\DesignerResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListDesigners extends ListRecords
|
||||
{
|
||||
protected static string $resource = DesignerResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DesignerResource\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class RidesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'rides';
|
||||
protected static ?string $title = 'Rides';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('manufacturer_name')
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('model_name')
|
||||
->maxLength(255),
|
||||
Forms\Components\DatePicker::make('opened_date')
|
||||
->label('Opening Date'),
|
||||
Forms\Components\DatePicker::make('closed_date')
|
||||
->label('Closing Date')
|
||||
->after('opened_date'),
|
||||
Forms\Components\Textarea::make('description')
|
||||
->columnSpanFull(),
|
||||
Forms\Components\Toggle::make('is_active')
|
||||
->label('Active')
|
||||
->default(true),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('manufacturer_name')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('opened_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('closed_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
Tables\Columns\IconColumn::make('is_active')
|
||||
->boolean()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
])
|
||||
->headerActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user