rjacobsen/eloquent-model-generator
Generate Eloquent models directly from your database schema. This Laravel package inspects existing tables and scaffolds model classes with fillable fields and column metadata, cutting boilerplate when working with legacy or evolving databases.
Install it as a dev-only dependency, since you should never need it in production:
composer require --dev rjacobsen/eloquent-model-generator
On Laravel 5.5+ the service provider is auto-discovered; on older 5.x add it to config/app.php under providers. It has no config file to publish in most versions — everything is driven by your existing config/database.php connection.
Then find the command it registers:
php artisan list | grep -i model
The package exposes a single generator command that walks information_schema (or the driver equivalent) for the configured connection and writes one model class per table. Run it against a scratch database first, into a directory you can inspect and delete:
php artisan model:generate # verify exact signature from `php artisan list`
Where to look first: the package's src/ directory — the console command class and the stub templates are the entire package. Read the stub before you run anything; it tells you exactly what $fillable, $table, $timestamps, and namespace conventions you'll get.
First real use case: you've inherited a legacy schema (or you're doing schema-first design and hand-wrote migrations) and you need 60 model classes before you can start writing application code. This package turns that afternoon into five minutes. It is a bootstrap tool, not a runtime dependency.
Generate on a throwaway branch, then curate. Commit the raw generator output in one commit, then a second commit where you delete the ~40% of models you'll never touch (log tables, pivot tables, migration bookkeeping, queue tables) and fix the rest by hand. This gives you a reviewable diff and an easy revert.
Treat the output as a stub, not a model. Generated classes typically give you a table name, timestamps guess, and a mass-assignment-friendly $guarded. Everything that carries application meaning — relationships, casts, accessors, scopes, soft deletes — is yours to write. Budget roughly 2–5 minutes per model for that pass.
Pair it with barryvdh/laravel-ide-helper. Run php artisan ide-helper:models --nowrite after generating so your editor knows about the columns before you've written a single relationship. This is where the package actually pays off: accurate autocomplete across a large unfamiliar schema.
Use it per-connection for multi-tenant or modular schemas. Point DB_CONNECTION at each database in turn, or generate into separate namespaces (App\Models\Billing, App\Models\Crm) and move the files. Keeps generated code from colliding on duplicate table names like users and settings.
Wire it into a scratch-project onboarding script. If you frequently spin up fresh developers against a legacy DB, a composer run generate-models script that runs the generator into a git-ignored directory is handy for exploration — just don't let it become part of the deploy pipeline.
Good downstream consumers: Nova/Backpack/Filament resource scaffolding, read-only reporting models against a replica connection, and factory/seeder generation (php artisan generate:model-factory style tooling reads the same schema).
composer.json constraint before installing on anything newer than 5.x; on Laravel 8+ you'll likely hit a hard conflict. If you're on a modern version, use reliese/laravel (php artisan code:models) instead — same idea, actively maintained, and it infers relationships and casts from foreign keys.--force guard or prompt.$guarded = [] or a $fillable that includes every column including is_admin, role, balance. Audit before shipping; this is the most common way this package causes a real bug.created_at/updated_at may still get $timestamps = true, producing silent insert failures (Column not found). Verify against $table->timestamps() in your migrations.reliese/laravel if relationships matter.people → Person usually works, but tbl_users → TblUser and user_data → UserDatum are surprises. Check the $table property explicitly on anything non-standard.php artisan tinker → DB::connection()->getDatabaseName()), that the user has information_schema read access, and that the output directory is writable. Bump verbosity (-v) if the command accepts it.declare(strict_types=1), readonly properties, custom base model). This is the only real customization hook the package offers.How can I help you explore Laravel packages today?