Create Models from database in Laravel 5

前端 未结 4 944
你的背包
你的背包 2020-12-13 13:13

Is there some way to generate models from database in Laravel 5?

The generators package only create an empty model.

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 13:41

    If you are using MySQL and Laravel 5.1 or above you can use php artisan code:models from this package: reliese/laravel. All you need to do is:

    1. composer require reliese/laravel
    2. Add the service provider to your config/app.php file Reliese\Coders\CodersServiceProvider::class
    3. Publish the config file with php artisan vendor:publish --tag=reliese-models
    4. Make sure your database is correctly configured in config/database.php and .env files.
    5. And finally issue the command: php artisan code:models

    This package will scan your database and create all models for you. If you need something more specific, you can customize its config file.

    Hope this helps :)

提交回复
热议问题