laravel-models
Laravel models
Covers everything that defines or exposes a domain model: the Eloquent model itself, its custom Builder and Filter, its migration, and the rule that its public reference is always the ULID identifier — never the numeric id.
1. Models
-
Use the
HasIdentifiertrait so a ULIDidentifiercolumn acts as the route key. -
Use Laravel's
HasBuildertrait when a model has a custom query builder. -
Add
SoftDeletesto most models. -
Define a
casts()method for enum/DTO casting (preferred over the$castsproperty). -
Because
HasIdentifieroverridesgetRouteKeyName()to return'identifier', route definitions resolve URL parameters to models via the ULID column automatically (the route-side syntax lives inlaravel-routing). -
After creating or changing a model, run:
php artisan ide-helper:models --write-mixin --reset --ansito refresh
_ide_helper_models.php. -
Always start Eloquent queries from
Model::query()so chained methods (->withTrashed(),->select(),->where(), …) line up neatly: