Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Eloquent Model Generator Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

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).

Gotchas and Tips

  • It's Laravel 5-era and effectively unmaintained (zero dependents, no stars). Check the 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.
  • It will happily overwrite your existing models. Always back up or be on a clean git tree before running. There is generally no --force guard or prompt.
  • Mass-assignment risk. Generated models often ship with $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.
  • Timestamps guessing is unreliable. Tables without created_at/updated_at may still get $timestamps = true, producing silent insert failures (Column not found). Verify against $table->timestamps() in your migrations.
  • No relationship inference. Foreign keys are ignored — you get 60 isolated models. This is the single biggest time cost and the main reason to prefer reliese/laravel if relationships matter.
  • Composite primary keys aren't supported by Eloquent, and the generator will pick one column arbitrarily. Same for views and materialized tables, which get models whether you want them or not.
  • Irregular plurals and prefix schemes mis-map. people → Person usually works, but tbl_users → TblUser and user_data → UserDatum are surprises. Check the $table property explicitly on anything non-standard.
  • Debugging a silent no-op: confirm the connection resolves (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.
  • Extension point: the stub templates are plain files in the package. Copy them into your own namespace and override the command subclass if you need a house style (final classes, declare(strict_types=1), readonly properties, custom base model). This is the only real customization hook the package offers.
  • Don't re-run it later. Once generated, the models are source code. Re-running after a migration will clobber your relationship methods. Add new models by hand or run the generator into a temp directory and diff.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel