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:
$fillablefrom real columns (PK, timestamps, soft-delete and token columns excluded)$castsinferred from column types —boolean,arrayfor json,datetime,date,decimal:N,float$table,$primaryKey,$keyType/$incrementing(UUID keys detected),$timestamps = falsewhen absentSoftDeleteswhen the table hasdeleted_at- Relationships inferred from foreign keys:
- FK on the table →
belongsTo - FK elsewhere pointing here →
hasMany(orhasOnewhen the FK is unique) - pivot tables (two FKs, no payload) →
belongsToManyon both sides {x}_id+{x}_typepairs →morphTo
- FK on the table →
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
$fillableentries that no longer exist in the schema - suggested
$castsyou 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/morphedByManyinverses 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