Laravel 从数据库或迁移脚本生成模型、视图和控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24052037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel generate models, views and controllers from database or migration script
提问by neeraj
I am new to Laravel 4. I wanted to know if it is possible to generate Models , Views and Controllers from existing database? I Googled and found
我是 Laravel 4 的新手。我想知道是否可以从现有数据库生成模型、视图和控制器?我用谷歌搜索发现
https://github.com/JeffreyWay/Laravel-4-Generators
But it allow to generate migration script, model, views and controllers by providing resource name where as i want to reverse engineering of the same in which by command line i want to create models, views and controllers from the existing database.
但是它允许通过提供资源名称来生成迁移脚本、模型、视图和控制器,因为我想对相同的资源进行逆向工程,我想通过命令行从现有数据库创建模型、视图和控制器。
回答by Jimbolino
I've had the same question, and couldn't find a good solution, so I started to build my own.
我有同样的问题,找不到好的解决方案,所以我开始构建自己的。
https://github.com/jimbolino/laravel-model-builder/
https://github.com/jimbolino/laravel-model-builder/
It's far from perfect, but is able to do the basic things like:
它远非完美,但能够做一些基本的事情,比如:
- Generate models
- Detect relations (probably buggy)
- Detect dates, auto increments
- Hidden fields (if you add a mysql comment)
- 生成模型
- 检测关系(可能有问题)
- 检测日期,自动递增
- 隐藏字段(如果添加mysql注释)
回答by Rokib
php artisan generate:model dbtablename
it will create individual model from your existing database. In this case you won't needthe generate:resource
command.
它将从您现有的数据库中创建单个模型。在这种情况下,您将不需要该generate:resource
命令。
php artisan generate:resource command
Laravel-4 Generatorsis very well documented. Read it thoroughly and you have fun.
Laravel-4 Generators有很好的文档记录。仔细阅读它,你会玩得很开心。
If you're using Laravel 5, you might want to consider the Laravel 5 Extended Generatorspackage.
如果您使用的是 Laravel 5,您可能需要考虑Laravel 5 Extended Generators包。
回答by Mohaimin Moin
Laravel 4 Migrations Generator: Automatically generates your migrations from an existing database schema. You will also find there the solution for Laravel-5.
Laravel 4 迁移生成器:从现有数据库模式自动生成迁移。您还将在那里找到 Laravel-5 的解决方案。
At packalyst.comyou will find how to generate the model automatically.
在packalyst.com,您将了解如何自动生成模型。