From fuse-laravel
Provides complete Eloquent ORM guidance for Laravel 13 with PHP 8.3 Attributes (#[Table], #[Fillable], #[Casts]) for models, relationships, queries, observers, and factories. Activates when working with database models.
How this skill is triggered — by the user, by Claude, or both
Slash command
/fuse-laravel:laravel-eloquentThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Before ANY implementation, use `TeamCreate` to spawn 3 agents:
references/accessors-mutators.mdreferences/aggregates.mdreferences/batch-operations.mdreferences/casts.mdreferences/collections.mdreferences/eager-loading.mdreferences/events-observers.mdreferences/factories.mdreferences/legacy-properties.mdreferences/models.mdreferences/pagination.mdreferences/performance.mdreferences/query-debugging.mdreferences/relationships-advanced.mdreferences/relationships-basic.mdreferences/relationships-many-to-many.mdreferences/relationships-polymorphic.mdreferences/resources.mdreferences/scopes.mdreferences/serialization.mdBefore ANY implementation, use TeamCreate to spawn 3 agents:
After implementation, run fuse-ai-pilot:sniper for validation.
Laravel 13 promotes PHP 8.3 Attributes as the primary metadata mechanism on Eloquent models. Legacy properties ($fillable, $hidden, ...) remain supported for backward compatibility but should not be mixed with their attribute counterparts.
| Feature | Attribute (L13 MAIN) | Legacy property |
|---|---|---|
| Table name | #[Table('users')] | protected $table |
| Mass assignment | #[Fillable([...])] | protected $fillable |
| Hidden / Visible | #[Hidden([...])] / #[Visible([...])] | protected $hidden / $visible |
| Guarded | #[Guarded([...])] / #[Unguarded] | protected $guarded |
| Casts | #[Casts([...])] | casts() method |
| Appends | #[Appends([...])] | protected $appends |
| Touches | #[Touches([...])] | protected $touches |
| Connection | #[Connection('mysql')] | protected $connection |
#[Fillable], #[Casts], #[Hidden] on new code#[Fillable] AND $fillable)with()new Model() in boot() - Throws LogicException in L13 (booted lifecycle protected)app/Models/
├── User.php # #[Table], #[Fillable], #[Hidden], #[Casts]
├── Post.php # #[Connection], #[Appends], relationships
└── Concerns/
└── HasUuid.php # Reusable trait
→ See templates/ModelBasic.php.md
| Template | When to Use |
|---|---|
| ModelBasic.php.md | Attribute-based model |
| ModelRelationships.php.md | All relationship types |
| ModelCasts.php.md | #[Casts] and accessors |
| Observer.php.md | Complete observer |
| Factory.php.md | Factory with states |
| Resource.php.md | API resource |
| EagerLoadingExamples.php.md | N+1 prevention |
use Illuminate\Database\Eloquent\Attributes\{Table, Fillable, Hidden, Casts};
use Illuminate\Database\Eloquent\Model;
#[Table('users')]
#[Fillable(['name', 'email', 'password'])]
#[Hidden(['password', 'remember_token'])]
#[Casts(['email_verified_at' => 'datetime', 'is_admin' => 'boolean'])]
final class User extends Model
{
public function posts(): HasMany
{
return $this->hasMany(Post::class);
}
}
#[Scope]
protected function published(Builder $query): void
{
$query->whereNotNull('published_at');
}
// Usage: Post::published()->get();
$posts = Post::with('author')->get(); // 2 queries, not N+1
→ Legacy $fillable / $hidden style — see legacy-properties.md
#[Table], #[Fillable], #[Casts], ...)final on model classes when not extendedwith()#[Casts]#[Fillable] and $fillable on the same model (conflict — single source of truth)boot() / booted() — L13 throws LogicException#[Unguarded] in productionnpx claudepluginhub fusengine/agents --plugin fuse-laravelMigrates Laravel Eloquent models, Jobs, Controllers, Console commands, API Resources, Validation, and Factories/Seeders to native PHP 8.3 attributes introduced in Laravel 13. Covers all 7 categories of first-party attributes.
Guides Laravel 13 development with 31 rules across architecture, Eloquent, controllers, validation, security, performance, and API design. Activates on tasks involving controllers, models, migrations, services, or database queries.
Provides best practices for Eloquent ORM: N+1 prevention, query scopes, mass assignment safety, relations, and aggregate performance.