init
This commit is contained in:
117
web10/app/Filament/Resources/CategoryResource.php
Normal file
117
web10/app/Filament/Resources/CategoryResource.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\CategoryResource\Pages;
|
||||
use App\Filament\Resources\CategoryResource\RelationManagers;
|
||||
use App\Models\Category;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class CategoryResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Category::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static ?string $navigationLabel = '分类';
|
||||
protected static ?string $navigationGroup = '内容管理';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('基础信息')
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('名称')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Select::make('parent_id')
|
||||
->label('父级分类')
|
||||
->relationship('parent', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->nullable(),
|
||||
TextInput::make('icon')
|
||||
->label('图标')
|
||||
->maxLength(255)
|
||||
->nullable(),
|
||||
Textarea::make('description')
|
||||
->label('描述')
|
||||
->rows(3)
|
||||
->nullable(),
|
||||
TextInput::make('sort')
|
||||
->label('排序')
|
||||
->numeric()
|
||||
->default(0),
|
||||
])->columns(2),
|
||||
Section::make('SEO')
|
||||
->schema([
|
||||
TextInput::make('seo_title')
|
||||
->label('SEO 标题')
|
||||
->maxLength(255)
|
||||
->nullable(),
|
||||
TextInput::make('seo_description')
|
||||
->label('SEO 描述')
|
||||
->maxLength(255)
|
||||
->nullable(),
|
||||
])->columns(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->reorderable('sort')
|
||||
->defaultSort('sort')
|
||||
->columns([
|
||||
TextColumn::make('name')->label('名称')->searchable()->sortable(),
|
||||
TextColumn::make('slug')->label('Slug')->searchable(),
|
||||
TextColumn::make('parent.name')->label('父级'),
|
||||
TextColumn::make('sort')->label('排序')->sortable(),
|
||||
TextColumn::make('created_at')->label('创建时间')->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user