How do I keep a unique constraint on a column like email while using soft deletes?
Use a partial unique index on deleted_at IS NULL in PostgreSQL and a generated column in MySQL, adding app validation beside the constraint, not instead.
Tag
Relations and queries with Laravel Eloquent: eager loading, N+1 traps and attribute casts. questions under this tag, answered directly.
6 answered questions carry this tag.
Use a partial unique index on deleted_at IS NULL in PostgreSQL and a generated column in MySQL, adding app validation beside the constraint, not instead.
Keep query rules in local scopes and test them against a real database; add a repository only when the domain genuinely has to decouple from Eloquent.
With 3 stable types and a real need for foreign keys, use a single-table exclusive arc; if the type set is open-ended, go pure morph with a morph map.
Use chunkById() when there is real per-row work and never touch the cursor column; if you only update a column, switch to one set-based UPDATE.
Integer cents in the DB, an immutable Money on the model: put the mapping in one CastsAttributes class and keep currency as a second column there.
Run it fully strict and throwing in local and CI; in production keep it on but wire handleLazyLoadingViolationUsing to log without failing the request.