Build modular Filament resources following strict conventions for Laravel models, UUIDs, enums, and field grouping
Generate clean, maintainable Filament resources using a modular architecture with enforced conventions for Laravel Eloquent models.
This skill guides you through creating Filament admin resources that follow a strict modular pattern:
Before creating any resource, examine the target model:
1. Read `app/Models/<ModelName>.php`
2. Identify all fillable fields
3. Note any casts, especially enums
4. Review relationships
5. Check nullable columns
6. Verify the model uses `HasUuid` trait and has `id`, `uuid`, `created_at`, `updated_at`
Organize fields into logical sections based on their purpose:
**Examples:**
Each group will become a separate field class file.
Execute the custom Artisan command with field groups:
```bash
php artisan make:modular-filament-resource <ModelName> --fields="Group One,Group Two,Group Three" [--generate] [--model] [--migration]
```
**Example:**
```bash
php artisan make:modular-filament-resource User --fields="Basic Info,Personal Info,Account Settings,Contact Info"
```
**Flags:**
Confirm the following files were created:
```
app/Filament/Resources/
├── <ModelName>Resource.php
└── <ModelName>Resource/
├── FormSchema.php
├── TableSchema.php
├── Actions.php
└── Fields/
├── GroupOne.php
├── GroupTwo.php
└── GroupThree.php
```
Each file in `Fields/` should:
1. Return a `Section` component with the group name
2. Use `->schema([])` to wrap related fields
3. Apply layout options like `->columns(2)`
4. Map model attributes to appropriate Filament field types
5. Use enum selects for enum-casted fields
**Example (`BasicInfo.php`):**
```php
<?php
namespace App\Filament\Resources\UserResource\Fields;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\TextInput;
class BasicInfo
{
public static function make(): Section
{
return Section::make('Basic Info')
->schema([
TextInput::make('name')
->required()
->maxLength(255),
TextInput::make('email')
->email()
->required()
->unique(ignoreRecord: true),
])
->columns(2);
}
}
```
Edit `TableSchema.php` to define columns:
**Rules:**
**Example:**
```php
TextColumn::make('email')
->toggleable()
->searchable(),
TextColumn::make('phone')
->toggleable()
->hidden(), // nullable field
BadgeColumn::make('status')
->enum(StatusEnum::class)
->toggleable(),
```
Edit `Actions.php` to centralize table and bulk actions:
```php
<?php
namespace App\Filament\Resources\UserResource;
use Filament\Tables\Actions;
class Actions
{
public static function getActions(): array
{
return [
Actions\ViewAction::make(),
Actions\EditAction::make(),
Actions\DeleteAction::make(),
];
}
public static function getBulkActions(): array
{
return [
Actions\BulkActionGroup::make([
Actions\DeleteBulkAction::make(),
]),
];
}
}
```
The main `<ModelName>Resource.php` should only contain:
```php
public static function form(Form $form): Form
{
return $form->schema(FormSchema::make());
}
public static function table(Table $table): Table
{
return $table
->columns(TableSchema::make())
->actions(Actions::getActions())
->bulkActions(Actions::getBulkActions());
}
```
No inline logic, field definitions, or action definitions should appear here.
Before creating any resource, verify the model follows these rules:
**Example Model:**
```php
<?php
namespace App\Models;
use App\Traits\HasUuid;
use App\Enums\StatusEnum;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use HasUuid;
protected $fillable = [
'name',
'email',
'status',
];
protected $casts = [
'status' => StatusEnum::class,
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
}
```
| Field Type | Suggested Group |
|------------|-----------------|
| name, title, slug | Basic Info |
| email, phone, address | Contact Info |
| status, role, permissions | Account Settings |
| date_of_birth, gender | Personal Info |
| tags, categories | Metadata |
| is_active, is_verified | Flags |
```php
Select::make('status')
->options(StatusEnum::class)
->required()
->default(StatusEnum::DRAFT),
```
```php
Select::make('category_id')
->relationship('category', 'name')
->searchable()
->preload(),
```
**Do NOT:**
**Always:**
1. User requests a Filament resource for a model
2. You read the model file to understand its structure
3. You identify logical field groups (3-5 groups typical)
4. You construct the modular command with `--fields`
5. You verify the generated file structure
6. You implement each field group with appropriate components
7. You configure table columns with toggleable/hidden rules
8. You define actions in the Actions class
9. You ensure the main Resource file remains clean
```bash
php artisan make:modular-filament-resource Product \
--fields="Basic Info,Pricing,Inventory,SEO,Media" \
--generate
```
This creates a fully modular Product resource with 5 field group files, auto-generated CRUD pages, and all supporting classes.
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/filament-modular-resource-builder/raw