2.5 KiB
2.5 KiB
Clean Code Guidelines for Filament Resources
This document outlines the coding standards and structure for Filament Resources in this project.
1. Class Properties
Properties within the Resource class should be ordered alphabetically.
Example:
protected static ?string $model = User::class;
protected static ?string $navigationGroup = 'Master';
protected static string|BackedEnum|null $navigationIcon = Heroicon::UserGroup;
protected static ?string $navigationLabel = 'Pengguna';
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $slug = 'master/users';
2. Form Structure
Form components should be structured with method calls in the following order:
- Basic:
make,label,placeholder - HTML Attributes:
autocomplete,autofocus, etc. - Validation:
required,maxLength,email,unique,regex, etc. - Filament/Logic:
relationship,live,afterStateUpdated, etc.
Formatting:
- Use a blank line between each component definition.
Example:
TextInput::make('name')
->label('Nama')
->placeholder('John Doe')
->autocomplete(false)
->autofocus()
->required()
->maxLength(100),
TextInput::make('email')
->label('Alamat Surel')
->placeholder('email@example.com')
->autocomplete(false)
->required()
->email(),
3. Table Structure
Columns
Column definitions should be structured in the following order:
- Basic:
make,label - Search & Sort:
searchable,sortable(These should be present for most fields) - State & Attributes:
getStateUsing,updateStateUsing,badge,icon - Formatting:
dateTime,money, etc.
Formatting:
- Use a blank line between each column definition.
Example:
TextColumn::make('name')
->label('Nama')
->searchable()
->sortable(),
ToggleColumn::make('is_active')
->label('Status')
->sortable()
->updateStateUsing(...),
Table Method Order
The methods chained to the $table object should follow this order:
columns([\ ... ])filters([\ ... ])recordActions([\ ... ])(oractions)toolbarActions([\ ... ])(orheaderActions)emptyStateIcon(...)emptyStateDescription(...)defaultSort(...)deferFilters(...)- Other configuration methods.
4. General Formatting
- Ensure consistent indentation.
- Always use a blank line to separate distinct logical blocks or component definitions to improve readability.