Skip to main content

Common Scenarios

Use this page when you want the fastest path from “I need X” to working commands and runtime structure.

Choose a scenario

  • First SQL CRUD API
  • Mongo document app
  • Blog with relations
  • Soft delete and restore
  • Cached GET endpoints
  • Test-isolated artifacts
  • Many-to-many favorites or tags
  • Casts, scopes, and serialization
  • Production-safe migrations

Scenario 1: First SQL CRUD API

Register models:
Wire Express routes with the generated controller and keep CRUD in the service layer. Recommended service CRUD shape:

Scenario 2: Mongo document app

Use MongoModel and explicit mongo connection names.

Scenario 3: Blog with relations

Use this when you want User, Post, Comment, favorites, and polymorphic comment flows quickly.

Scenario 4: Soft delete and restore

Generate restore-ready controller:
Use one schema declaration:
or:

Scenario 5: Cache GET endpoints

Keep cache logic in services:
Read from cache before query execution and invalidate after writes. Recommended write-side invalidation:

Scenario 6: Test-isolated artifacts

Scenario 7: Many-to-many favorites or tags

Use service-level attach, detach, and sync flows for pivot management.

Scenario 8: Casts, scopes, and serialization

  • casts normalize service reads
  • scopes filter all() and find()
  • toObject() gives API-safe output
Example:

Scenario 9: Production-safe migrations

Recommended order:
  1. eloquent migrate:status
  2. eloquent db:seed:precheck --all-connections
  3. eloquent migrate:run --all-migrations
  4. destructive flows only with explicit --force --yes

Next detailed guides