Laravel Model Studio

v0.0.1
g4t/laravel-model-studio

Eloquent model studio for Laravel — generates models with relationships and casts from your migration files, and detects drift between your schema and existing models.

Dev Tools
Install via Composer
$ composer require g4t/laravel-model-studio
Health Score
Fair
○ Downloads ○ Stars ✓ Versioned ✓ Docs
Badges
Latest Version
Downloads
License
Ask AI about this package
Powered by DeepWiki. Ask anything about the code, usage, or design.

g4t Model Studio

Generate Eloquent models from your migration files — and keep them in sync forever.

Model Studio reads your schema the same way g4t/schema-designer does: by replaying migrations against a capturing schema builder (zero SQL, zero database introspection). It then compares that schema against the models in app/Models and gives you a studio UI where every table is either missing (one click generates a complete model), drifted (you get a precise report with paste-ready fixes), or synced.

Installation

composer require g4t/model-studio

The service provider is auto-discovered. Open the studio at:

http://your-app.test/model-studio

What it generates

For a table like orders, Model Studio produces a complete model:

  • $fillable from real columns (PK, timestamps, soft-delete and token columns excluded)
  • $casts inferred from column types — boolean, array for json, datetime, date, decimal:N, float
  • $table, $primaryKey, $keyType/$incrementing (UUID keys detected), $timestamps = false when absent
  • SoftDeletes when the table has deleted_at
  • Relationships inferred from foreign keys:
    • FK on the table → belongsTo
    • FK elsewhere pointing here → hasMany (or hasOne when the FK is unique)
    • pivot tables (two FKs, no payload) → belongsToMany on both sides
    • {x}_id + {x}_type pairs → morphTo

Drift reports

For tables that already have a model, Model Studio never touches your file. Instead it reports:

  • columns missing from $fillable (models using the $guarded = [] style are respected and skipped)
  • stale $fillable entries that no longer exist in the schema
  • suggested $casts you haven't declared
  • relation methods that should exist — each one as a paste-ready snippet with a fully-qualified return type

Compatibility

Laravel 8.x, 9.x, 10.x, 11.x, 12.x, 13.x
PHP ^8.0
Databases Driver-agnostic — the schema comes from Blueprint capture, not from your DB.

Configuration

php artisan vendor:publish --tag=model-studio-config
Key Default Purpose
enabled null null → available everywhere except production. Override with MODEL_STUDIO_ENABLED=true/false.
path model-studio Route prefix.
middleware ['web'] Add auth etc. to protect the UI.
models_path app_path('Models') Where models are scanned and written.
models_namespace App\Models Namespace for scanned and generated models.
ignore_tables framework tables Tables that should never get models (migrations, jobs, cache, spatie pivot tables, …).

Guarantees

  • Existing models are never overwritten — drift is reported, fixes are copy-paste snippets, and the write endpoint refuses tables that already have a model.
  • Your database is never queried — the schema comes entirely from migration files.
  • Generation is previewed in the UI before any file is written.

Known limits

  • Relations are inferred from real foreign key constraints — implicit relationships without FK constraints aren't detected.
  • morphMany/morphedByMany inverses can't be inferred reliably and are left to you.
  • Drift checks cover $fillable, $casts, and relation methods — not accessors, scopes, or observers (those are yours).

License

MIT

laravel-model-studio