Files
nexusphp/app/Filament/Resources/Section/CategoryResource.php

115 lines
4.2 KiB
PHP
Raw Normal View History

2022-09-07 17:10:52 +08:00
<?php
2022-10-27 20:21:54 +08:00
namespace App\Filament\Resources\Section;
2022-09-07 17:10:52 +08:00
2022-10-27 20:21:54 +08:00
use App\Filament\Resources\Section\CategoryResource\Pages;
use App\Filament\Resources\Section\CategoryResource\RelationManagers;
use App\Models\Category;
2022-09-13 02:41:10 +08:00
use App\Models\Icon;
2022-10-27 20:21:54 +08:00
use App\Models\SearchBox;
2022-09-07 17:10:52 +08:00
use Filament\Forms;
use Filament\Resources\Form;
2022-10-27 20:21:54 +08:00
use Filament\Resources\Resource;
2022-09-07 17:10:52 +08:00
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
2022-10-27 20:21:54 +08:00
class CategoryResource extends Resource
2022-09-07 17:10:52 +08:00
{
2022-10-27 20:21:54 +08:00
protected static ?string $model = Category::class;
2022-09-07 17:10:52 +08:00
2022-10-27 20:21:54 +08:00
protected static ?string $navigationIcon = 'heroicon-o-collection';
2022-09-07 17:10:52 +08:00
2022-10-27 20:21:54 +08:00
protected static ?string $navigationGroup = 'Section';
protected static ?int $navigationSort = 2;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.category');
}
public static function getBreadcrumb(): string
2022-09-07 17:10:52 +08:00
{
2022-10-27 20:21:54 +08:00
return self::getNavigationLabel();
2022-09-07 17:10:52 +08:00
}
public static function form(Form $form): Form
{
return $form
->schema([
2022-10-27 20:21:54 +08:00
Forms\Components\Select::make('mode')
->options(SearchBox::query()->pluck('name', 'id')->toArray())
->label(__('label.search_box.label'))
->required()
,
Forms\Components\TextInput::make('name')->required()->label(__('label.search_box.taxonomy.name'))->required(),
2022-09-07 17:10:52 +08:00
Forms\Components\TextInput::make('image')
->label(__('label.search_box.taxonomy.image'))
->helperText(__('label.search_box.taxonomy.image_help'))
->required()
2022-09-07 17:10:52 +08:00
,
2022-09-13 02:41:10 +08:00
Forms\Components\Select::make('icon_id')
->options(Icon::query()->pluck('name', 'id')->toArray())
->label(__('label.search_box.taxonomy.icon_id'))
->required()
2022-09-13 02:41:10 +08:00
,
2022-09-07 17:10:52 +08:00
Forms\Components\TextInput::make('class_name')
->label(__('label.search_box.taxonomy.class_name'))
->helperText(__('label.search_box.taxonomy.class_name_help'))
,
Forms\Components\TextInput::make('sort_index')
->default(0)
->label(__('label.search_box.taxonomy.sort_index'))
->helperText(__('label.search_box.taxonomy.sort_index_help'))
,
2022-10-27 20:21:54 +08:00
2022-09-07 17:10:52 +08:00
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id'),
2022-10-27 20:21:54 +08:00
Tables\Columns\TextColumn::make('search_box.name')->label(__('label.search_box.label')),
Tables\Columns\TextColumn::make('name')->label(__('label.search_box.taxonomy.name'))->searchable(),
2022-09-13 02:41:10 +08:00
Tables\Columns\TextColumn::make('icon.name')->label(__('label.search_box.taxonomy.icon_id')),
2022-09-07 17:10:52 +08:00
Tables\Columns\TextColumn::make('image')->label(__('label.search_box.taxonomy.image')),
Tables\Columns\TextColumn::make('class_name')->label(__('label.search_box.taxonomy.class_name')),
Tables\Columns\TextColumn::make('sort_index')->label(__('label.search_box.taxonomy.sort_index'))->sortable(),
2022-09-07 17:10:52 +08:00
])
2022-10-27 20:21:54 +08:00
->defaultSort('sort_index', 'asc')
2022-09-07 17:10:52 +08:00
->filters([
2022-10-27 20:21:54 +08:00
Tables\Filters\SelectFilter::make('mode')
->options(SearchBox::query()->pluck('name', 'id')->toArray())
->label(__('label.search_box.label'))
,
2022-09-07 17:10:52 +08:00
])
->actions([
2022-10-27 20:21:54 +08:00
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
2022-09-07 17:10:52 +08:00
])
->bulkActions([
2022-10-27 20:21:54 +08:00
Tables\Actions\DeleteBulkAction::make(),
2022-09-07 17:10:52 +08:00
]);
}
2022-10-27 20:21:54 +08:00
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'),
];
}
2022-09-07 17:10:52 +08:00
}