- Fully transitioned the backend to the Porto architectural pattern - Improved code organization and maintainability - Fixed minor bugs and inconsistencies
89 lines
2.9 KiB
PHP
89 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Containers\Article\Models\Category;
|
|
use App\Filament\Resources\CategoryResource\Pages;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Support\Str;
|
|
|
|
class CategoryResource extends Resource
|
|
{
|
|
protected static ?string $model = Category::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
protected static ?string $navigationGroup = 'Новости и мероприятия';
|
|
|
|
|
|
protected static ?string $pluralLabel = 'Категории';
|
|
protected static ?string $navigationParentItem = 'Новости';
|
|
|
|
protected static ?int $navigationSort = 2;
|
|
|
|
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\Section::make()->schema([
|
|
Forms\Components\Grid::make(2)->schema([
|
|
TextInput::make('title')->label('Заголовок')->required()
|
|
->live(onBlur: true)
|
|
->afterStateUpdated(function (string $operation, string|null $state, Forms\Set $set) {
|
|
$set('slug', Str::slug($state));
|
|
}),
|
|
TextInput::make('slug')->label('Slug')->unique(ignoreRecord: true)->readOnly()->required(),
|
|
]),
|
|
Toggle::make('is_active')->default(true)->label('Активно')->inline(false),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('id')->label('ID')->sortable(),
|
|
TextColumn::make('title')->label('Название')->sortable()->searchable(),
|
|
TextColumn::make('created_at')->label('Дата создания')->sortable(),
|
|
Tables\Columns\ToggleColumn::make('is_active')->label('Активно')->sortable(),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListCategories::route('/'),
|
|
'create' => Pages\CreateCategory::route('/create'),
|
|
'edit' => Pages\EditCategory::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|