Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

smanes's avatar

Is there a utility to create Model files from an existing database?

New to Laravel but we had something like this for Symfony2.

I tried ignasbernotas/laravel-model-generator but after loading it via composer the "artisan make:models" command came back with:

[Symfony\Component\Console\Exception\CommandNotFoundException] Command "make:models" is not defined. Did you mean one of these? make:model make:auth make:command ...

Basically, I have a complex database designed in an ERD that would be a major PITA to recreated in model files manually.

The database is PostgreSQL 9.6.

0 likes
4 replies
smanes's avatar

This one failed too. I wonder if I'm doing something wrong with 'composer':

root@paco:/web/hrl# composer require krlove/eloquent-model-generator --dev

Using version ^1.2 for krlove/eloquent-model-generator ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files

Illuminate\Foundation\ComposerScripts::postUpdate php artisan optimize

[Doctrine\DBAL\Driver\PDOException] SQLSTATE[HY000] [2002] Connection refused

[PDOException] SQLSTATE[HY000] [2002] Connection refused

Script php artisan optimize handling the post-update-cmd event returned with an error

Installation failed, reverting ./composer.json to its original content.

[RuntimeException] Error Output:

require [--dev] [--prefer-source] [--prefer-dist] [--no-plugins] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] []...

kevuno's avatar

You probably didn't register the model generator library correctly:

Add the provider in app/Providers/AppServiceProvider.php, like so:

public function register() { if ($this->app->environment() == 'local') { $this->app->register('Iber\Generator\ModelGeneratorProvider'); } }

I would recommend executing composer update and clear the cache using artisan:

php artisan cache:clear

This happens to me constantly after installing a new dependency.

smanes's avatar

I did bungle that register() function. However it looks like ignasbernotas/laravel-model-generator is hard-wired for MySQL. I'm using PostgreSQL 9.6 here.

//'default' => env('DB_CONNECTION', 'mysql'),
'default' => env('DB_CONNECTION', 'pgsql'),

smanes@paco:/web/hrl# php artisan make:models

[Illuminate\Database\QueryException] SQLSTATE[HY000] [2002] Connection refused (SQL: SELECT table_name AS name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema = 'homestead')

[PDOException] SQLSTATE[HY000] [2002] Connection refused

Please or to participate in this conversation.