Runtime CRUD
This page defines the recommended CRUD contract for application code.Core rule
Use one of these two creation paths:new User()means a transient in-memory model instancesave()persists the current instance stateUser.create(...)persists immediately and returns the created model
User.create(...) and save() as the same step.
Create
Use new User() when
- you want to build the model gradually
- you want to call
fill(...)before persistence - the code reads better as an explicit instance lifecycle
Use User.create(...) when
- the payload is already validated
- you want a one-shot insert
- you want a concise service method
save() after User.create(...) unless you changed the model again.
Use User.createMany(...) when
- you already have multiple validated payloads
- the service owns an explicit bulk insert operation
- you want hydrated created models back in input order
Read
Use primary-key and safe-finder reads before mutation:new User().all() when you explicitly want the instance collection-read path:
Update
Recommended loaded-instance update
This is the preferred public runtime path:- the record is loaded first
- the code reads like a model lifecycle
- it works well with dirty tracking, hooks, and service-level decisions
Partial update with patch()
Use patch() when the instance already exists and you are intentionally updating a subset of fields.
patch() when:
- the row is already loaded
- the service is applying a narrow change
- you do not want the full
update(...); save()flow
Bulk update and patch
Use bulk helpers only when the service already owns an explicit list of ids or patch rows.Delete
Recommended loaded-instance delete
- the code reads as “load then delete”
- soft-delete behavior stays attached to the model runtime
- service logic can branch on “record exists” before deletion
Restore
Restore applies only when the model supports soft deletes.Recommended loaded-instance restore
- the model includes soft-delete behavior
- the service is intentionally exposing record recovery
- the controller is generated with or supports a restore route
Bulk delete and restore
Explicit by-id helpers
Use these helpers only when you intentionally want a direct by-id service path:- the service already owns the target primary key
- you do not want the full loaded-instance lifecycle
- the code is intentionally thin and explicit
Recommended service pattern
What is not the recommended shape
Do not treat these as the primary public teaching path:new User().create(...)new User().update(id, data)new User().delete(id)