Laravel 5.4 在单个工匠命令中创建模型、控制器和迁移

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43187735/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:42:39  来源:igfitidea点击:

Laravel 5.4 create model, controller and migration in single artisan command

laravellaravel-5.4artisan

提问by arun

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?

我还想用上面的命令创建一个迁移,这可能吗?

回答by Christophvh

You can do it if you start from the model

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

php artisan make:model Todo -mcr

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

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

-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

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

Update

更新

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

正如@arun 在较新版本的 laravel > 5.6 中的评论中提到的,可以运行以下命令:

php artisan make:model Todo -a

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

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

回答by Udhav Sarvaiya

You can make model+ migration+ controller, all in one line, using this command:

您可以使用以下命令在一行中创建模型+迁移+控制器

php artisan make:model --migration --controller test

Short version: php artisan make:model -mc test

精简版: php artisan make:model -mc test

Output :-

输出 :-

Model created successfully.

Created Migration:2018_03_10_002331_create_tests_table

Controller created successfully.

模型创建成功。

创建迁移:2018_03_10_002331_create_tests_table

控制器创建成功。



If you need to perform all CRUDoperations in the controllerthen use this command:

如果您需要在控制器中执行所有CRUD操作,请使用以下命令:

php artisan make:model --migration --controller test --resource  

Short version: php artisan make:model -mc test --resource

精简版: php artisan make:model -mc test --resource

回答by sunil

You can do it with the following command:

您可以使用以下命令执行此操作:

php artisan make:model post -mcr

Brief :

简短的 :

-m, to create migration

-m,创建迁移

-c to create controller

-c 创建控制器

-r to specify the controller has resource

-r 指定控制器有资源

回答by gedeadisurya

php artisan make:model PurchaseRequest -crm

The Result is

结果是

Model created successfully.
Created Migration: 2018_11_11_011541_create_purchase_requests_table
Controller created successfully.

Just use -crminstead of -mcr

只需使用-crm而不是 -mcr

回答by Arman H

Updated

更新

Laravel 6 Through the model

Laravel 6 通过模型

To Generate a migration, seeder, factory, and resource controller for the model

为模型生成迁移、播种器、工厂和资源控制器

php artisan make:model Todo -a

Or

或者

php artisan make:model Todo -all

Other Options

其他选项

-c, --controllerCreate a new controller for the model

-c, --controller为模型创建一个新的控制器

-f, --factoryCreate a new factory for the model

-f, --factory为模型创建一个新工厂

--forceCreate the class even if the model already exists

--force即使模型已经存在也要创建类

-m, --migrationCreate a new migration file for the model

-m, --migration为模型创建一个新的迁移文件

-s, --seedCreate a new seeder file for the model

-s, --seed为模型创建一个新的播种机文件

-p, --pivotIndicates if the generated model should be a custom inte rmediate table model

-p, --pivot指示生成的模型是否应该是自定义的中间表模型

-r, --resourceIndicates if the generated controller should be a resour ce controller

-r, --resource指示生成的控制器是否应该是资源控制器

For More Help

更多帮助

php artisan make:model Todo -help

Hope Newbies will get help.

希望新人得到帮助。

回答by Affan

Laravel 5.4 You can use

Laravel 5.4 你可以使用

 php artisan make:model --migration --controller --resource Test

This will create 1) Model 2) controller with default resource function 3) Migration file

这将创建 1) 模型 2) 具有默认资源功能的控制器 3) 迁移文件

And Got Answer

得到了答案

Model created successfully.

模型创建成功。

Created Migration: 2018_04_30_055346_create_tests_table

创建迁移:2018_04_30_055346_create_tests_table

Controller created successfully.

控制器创建成功。

回答by Prakash Pazhanisamy

We can use php artisan make:model Todo -ato create model, migration, resource controller and factory

我们可以php artisan make:model Todo -a用来创建模型、迁移、资源控制器和工厂

回答by Nirmal Khadka

To make mode, controllers with resources, You can type CMD as follows :

要使模式,控制器具有资源,您可以键入 CMD 如下:

 php artisan make:model Todo -mcr

or you can check by typing

或者您可以通过键入来检查

php artisan help make:model

where you can get all the ideas

在那里你可以得到所有的想法

回答by Deepak singh Thakur

You can use -m -c -r to make migration, model and controller.

您可以使用 -m -c -r 进行迁移、模型和控制器。

php artisan make:model Post -m -c -r

回答by clusterBuddy

To make all 3: Model, Controller & Migration Schema of table

使所有 3:表的模型、控制器和迁移模式

write in your console: php artisan make:model NameOfYourModel -mcr

在你的控制台中写: php artisan make:model NameOfYourModel -mcr