labrodev-modellisted
Install: claude install-skill labrodev/laravel-playbook
# Models, Collections, and Observers
Part of the Labrodev playbook. **The law for this component lives in the always-on `labrodev-model` guideline** (musts, must-nots); the per-file checklists are `rules/models.md` and `rules/migrations.md`. This skill holds the craft: anatomy, canonical templates, and edge cases.
This skill covers five templates in order: the shared `BaseModel` every model extends, the model itself, its Collection, its Observer, and the migration that backs it. **Every model ships with its full trio — Policy (→ labrodev-authorization skill), Observer, and Collection — always**; none of the three is optional or deferred.
## BaseModel (shared, one per project)
Location: `Core/Shared/Models/BaseModel.php`. All domain models extend it.
Responsibilities: blocks mass assignment for every model (`$guarded = ['*']`), centralizes hidden fields, enables `Model::factory()` for models declaring `#[UseFactory]`. Business logic never lives here; concrete models use `$visible` instead of overriding `$hidden`.
```php
<?php
declare(strict_types=1);
namespace Core\Shared\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
abstract class BaseModel extends Model
{
/** @use HasFactory<\Illuminate\Database\Eloquent\Factories\Factory> */
use HasFactory;
protected $guarded = ['*'];
protected $hidden = [
'created_by',
'updated_by',
'deleted_at',
'created_at',
'updat