finished the upgrade to filament 4. completely revamped the frontend with codex, now it looks great!
This commit is contained in:
158
app/Filament/Resources/Styles/StyleResource.php
Normal file
158
app/Filament/Resources/Styles/StyleResource.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\StyleResource\Pages;
|
||||
use App\Models\Style;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
|
||||
class StyleResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Style::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->columns('full')
|
||||
->schema([
|
||||
Forms\Components\Tabs::make('Style Details')
|
||||
->tabs([
|
||||
Forms\Components\Tabs\Tab::make('General')
|
||||
->schema([
|
||||
Forms\Components\Grid::make(2)
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->label(__('filament.resource.style.form.title'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Toggle::make('enabled')
|
||||
->label(__('filament.resource.style.form.enabled'))
|
||||
->default(true),
|
||||
]),
|
||||
Forms\Components\Grid::make(2)
|
||||
->schema([
|
||||
Textarea::make('prompt')
|
||||
->label(__('filament.resource.style.form.prompt'))
|
||||
->required()
|
||||
->rows(5),
|
||||
Textarea::make('description')
|
||||
->label(__('filament.resource.style.form.description'))
|
||||
->required()
|
||||
->rows(5),
|
||||
]),
|
||||
Select::make('ai_model_id')
|
||||
->relationship('aiModel', 'name')
|
||||
->label(__('filament.resource.style.form.ai_model'))
|
||||
->required(),
|
||||
FileUpload::make('preview_image')
|
||||
->label(__('filament.resource.style.form.preview_image'))
|
||||
->disk('public')
|
||||
->directory('style_previews')
|
||||
->image()
|
||||
->imageEditor()
|
||||
->required()
|
||||
->rules(['mimes:jpeg,png,bmp,gif,webp']),
|
||||
]),
|
||||
Forms\Components\Tabs\Tab::make('Details')
|
||||
->schema([
|
||||
|
||||
Forms\Components\TextInput::make('sort_order')
|
||||
->numeric()
|
||||
->default(0)
|
||||
->label(__('filament.resource.style.form.sort_order')),
|
||||
Textarea::make('parameters')
|
||||
->label(__('filament.resource.style.form.parameters'))
|
||||
->nullable()
|
||||
->rows(15)
|
||||
->json()
|
||||
->helperText(__('filament.resource.style.form.parameters_help'))
|
||||
->formatStateUsing(fn (?array $state): ?string => $state ? json_encode($state, JSON_PRETTY_PRINT) : null),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('sort_order')
|
||||
->reorderable('sort_order')
|
||||
->columns([
|
||||
TextColumn::make('title')->label(__('filament.resource.style.table.title'))->searchable()->sortable(),
|
||||
IconColumn::make('enabled')
|
||||
->label(__('filament.resource.style.table.enabled'))
|
||||
->boolean(),
|
||||
TextColumn::make('aiModel.name')->label(__('filament.resource.style.table.ai_model'))->searchable()->sortable(),
|
||||
ImageColumn::make('preview_image')->label(__('filament.resource.style.table.preview_image'))->disk('public'),
|
||||
TextColumn::make('sort_order')->label(__('filament.resource.style.table.sort_order'))->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('ai_model')
|
||||
->relationship('aiModel', 'name')
|
||||
->label(__('filament.resource.style.table.ai_model')),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\Action::make('duplicate')
|
||||
->label(__('filament.resource.style.action.duplicate'))
|
||||
->icon('heroicon-o-document-duplicate')
|
||||
->action(function (\App\Models\Style $record) {
|
||||
$newStyle = $record->replicate();
|
||||
$newStyle->title = $record->title . ' (Kopie)';
|
||||
$newStyle->save();
|
||||
|
||||
return redirect()->to(StyleResource::getUrl('edit', ['record' => $newStyle->id]));
|
||||
}),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\BulkAction::make('enable')
|
||||
->label(__('filament.resource.style.action.enable_selected'))
|
||||
->icon('heroicon-o-check-circle')
|
||||
->action(function (\Illuminate\Support\Collection $records) {
|
||||
$records->each->update(['enabled' => true]);
|
||||
}),
|
||||
Tables\Actions\BulkAction::make('disable')
|
||||
->label(__('filament.resource.style.action.disable_selected'))
|
||||
->icon('heroicon-o-x-circle')
|
||||
->action(function (\Illuminate\Support\Collection $records) {
|
||||
$records->each->update(['enabled' => false]);
|
||||
}),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListStyles::route('/'),
|
||||
'create' => Pages\CreateStyle::route('/create'),
|
||||
'edit' => Pages\EditStyle::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user