Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
557 views
in Technique[技术] by (71.8m points)

eloquent - Create Models from database in Laravel

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

The generators package only create an empty model.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Warning, you may end up overwriting your JetStream or any other scaffolding models. take backup of them before overwriting them.

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 RelieseCodersCodersServiceProvider::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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...