Laravel 5.4在单个工匠命令中创建模型,控制器和迁移 [英] Laravel 5.4 create model, controller and migration in single artisan command

查看:169
本文介绍了Laravel 5.4在单个工匠命令中创建模型,控制器和迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下命令创建模型和资源控制器(绑定到模型)

I can create a model and resource controller (binded to model) with the following command

php artisan make:controller TodoController --resource --model=Todo

我还想使用上述命令创建迁移,可以吗?

I want to also create a migration with the above command, is it possible?

推荐答案

如果您从模型开始,就可以做到

You can do it if you start from the model

php artisan make:model Todo -mcr

如果您运行php artisan make:model --help,则可以看到所有可用选项

if you run php artisan make:model --help you can see all the available options

-m,--migration为模型创建一个新的迁移文件.
-c,--controller为模型创建一个新的控制器.
-r,--resource指示生成的控制器是否应为资源控制器

-m, --migration Create a new migration file for the model.
-c, --controller Create a new controller for the model.
-r, --resource Indicates if the generated controller should be a resource controller

更新

如更新版本的laravel> 5.6中@arun的评论中所述,可以运行以下命令:

As mentioned in the comments by @arun in newer versions of laravel > 5.6 it is possible to run following command:

php artisan make:model Todo -a

-a,--all生成迁移,工厂和资源 模型的控制器

-a, --all Generate a migration, factory, and resource controller for the model

这篇关于Laravel 5.4在单个工匠命令中创建模型,控制器和迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆