Usage Guides
1) Runtime setup
- Configure
.env. - Set
DB_CONNECTION. - Register models at startup:
2) Migration workflow
3) Seeding workflow
4) Multi-driver workflow
- Single target:
--mysql,--pg,--sqlite - All SQL connections:
--all-connections - Mongo target (SQL-only excluded):
--mongo,--mongo --test - For one app talking to different drivers at once, keep one
DB_CONNECTIONfallback and pinstatic connectionNameon the models that must stay on a specific driver
5) Test mode workflow
6) Recovery and safety
- Use
--force --yeswith production guard checks for destructive operations. - Prefer least-privilege credentials:
ELOQUENT_DB_ROLE=runtimeELOQUENT_DB_ROLE=migration
- Keep CLI prechecks in place before
--all-connectionsseed runs.
7) NoSQL quick path
Use explicit target flags and keep SQL operations out of implicit scopes.8) Runtime querying patterns
Important: runtime querying contract
The runtime read API is Laravel-like and should stay aligned with the public CRUD contract.- static safe-finder helpers such as
User.where(...),User.orderBy(...),User.first(), andUser.findOneBy(...) - static primary-key reads such as
User.find(id) - instance collection reads such as
new User().all() - eager-loading helpers such as
with(...)andload(...)when explicit relation methods exist
- use static query helpers for filtered reads
- use
findOneBy(...)orfirst()when you want one record ornull - use
get()when you want hydrated arrays - use
with(...)only when the model exposes explicit relation methods
9) Runtime CRUD patterns
Important: runtime CRUD contract
The runtime write API is intentionally split into three layers:User.create(data)- create a new row or document
- loaded instance methods such as
update(),fill(),save(),delete(),restore(), andpatch()- update an already loaded model instance
- explicit low-level by-id methods such as
User.updateById(id, data),User.deleteById(id), andUser.restoreById(id)- direct writes when you already know the primary key
- read with query helpers
- update with
update() + save()orpatch()on a loaded instance - use
User.updateById(...),User.deleteById(...), andUser.restoreById(...)only when you intentionally want a direct by-id service path - use bulk helpers only when the service already owns a concrete list of ids or row payloads
10) Cache in read paths
Use cache at the service boundary, not in controllers.APP_ENV=development: memory cacheAPP_ENV=staging: file cache usingCACHE_DIRAPP_ENV=production: Memcached, then file cache, then memory cache
11) Model implementation by driver
SQL runtime model
Mongo runtime model
--mongo flows.