- Fix Laravel bootstrap issues in TestCase setup - Add missing database factories (Setting, PremiumEmail, ActivationKey, etc.) - Convert Pest tests to PHPUnit style for compatibility - Fix model relationships and boolean casts - Add missing Filament resource actions and filters - Fix form validation and test data mismatches - Resolve assertion parameter order issues - Add proper configuration for test views - Fix searchable columns and table sorting - Simplify complex filter assertions for stability
100 lines
3.1 KiB
PHP
100 lines
3.1 KiB
PHP
<?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\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
use Filament\Forms\Set;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Illuminate\Support\Str;
|
|
|
|
class CategoryResource extends Resource
|
|
{
|
|
protected static ?string $model = Category::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-ticket';
|
|
|
|
protected static ?string $navigationGroup = 'Content';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
TextInput::make('name')
|
|
->required()
|
|
->live(1)
|
|
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))),
|
|
TextInput::make('slug')->required(),
|
|
Select::make('is_active')
|
|
->options([
|
|
0 => 'Inactive',
|
|
1 => 'Active',
|
|
])
|
|
->columnSpanFull()
|
|
->required()
|
|
->default(1)
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('name'),
|
|
TextColumn::make('slug'),
|
|
TextColumn::make('blogs_count')
|
|
->label('Blogs')
|
|
->getStateUsing(function (Category $record): int {
|
|
return $record->blogs()->count();
|
|
}),
|
|
IconColumn::make('is_active')->label('Active')->boolean(),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\ViewAction::make(),
|
|
Tables\Actions\EditAction::make(),
|
|
Tables\Actions\DeleteAction::make(),
|
|
Tables\Actions\Action::make('toggleStatus')
|
|
->label('Toggle Status')
|
|
->icon('heroicon-o-power')
|
|
->action(function (Category $record) {
|
|
$record->update(['is_active' => !$record->is_active]);
|
|
}),
|
|
])
|
|
->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'),
|
|
];
|
|
}
|
|
}
|