php 生成控制器和模型

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

Generate Controller and Model

phplaravel

提问by Sophy

I am newbie with Laravel and I played around laravel 4(Beta version). I want to know how to generate Controller and Model by command line use php artisan. But I don't know how to do them.

我是 Laravel 的新手,我玩过 Laravel 4(Beta 版)。我想知道如何通过命令行使用生成控制器和模型php artisan。但我不知道该怎么做。

回答by Barryvdh

See this video: http://youtu.be/AjQ5e9TOZVk?t=1m45sYou can do php artisan listto view all commands, The command for generating REST-ful controllers is controller:makeYou can view the usage with: php artisan help make:controller

看这个视频:http: //youtu.be/AjQ5e9TOZVk?t=1m45s你可以php artisan list查看所有命令,生成REST-ful控制器的命令是controller:make你可以查看用法:php artisan help make:controller

回答by DutGRIFF

Laravel 5

Laravel 5

The other answers are great for Laravel 4 but Laravel 5is here! We now have the ability to generate all kinds of stuff by default. Run php artisan helpto view all artisan commands. Here are all of the makecommands:

其他答案对 Laravel 4 很好,但Laravel 5就在这里!我们现在可以默认生成各种东西。运行php artisan help以查看所有工匠命令。以下是所有make命令:

make
  make:command         Create a new command class
  make:console         Create a new Artisan command
  make:controller      Create a new resource controller class
  make:event           Create a new event class
  make:middleware      Create a new middleware class
  make:migration       Create a new migration file
  make:model           Create a new Eloquent model class
  make:provider        Create a new service provider class
  make:request         Create a new form request class

Note:we no longer use item:make. Instead we now have make:item.

注意:我们不再使用item:make。相反,我们现在有 make: item

Run php artisan help make:itemto see what you can pass it. For instance php artisan help make:migrationshows that we need to pass it the migration name but we can also pass it --create=""or --table=""to specify the table name to create or modify respectively. Run php artisan make:migration create_articles_table --create="articles"to generate the articles table. Moreover, generating models takes care of generating the migration for that model. Follow the naming conventions and it will be pluralized it for the migration.

跑去php artisan help make:item看看你能通过什么。例如php artisan help make:migration显示我们需要将迁移名称传递给它,但我们也可以传递它--create=""--table=""指定要分别创建或修改的表名。运行php artisan make:migration create_articles_table --create="articles"以生成文章表。此外,生成模型负责为该模型生成迁移。遵循命名约定,它将为迁移而复数化。

回答by Sophy

Thank you @user1909426, I can found solution by php artisan listit will list all command that was used on L4. It can create controller only not Model. I follow this command to generate controller.

谢谢@user1909426,我可以找到解决方案,php artisan list它会列出在 L4 上使用的所有命令。它只能创建控制器不能创建模型。我按照这个命令来生成控制器。

php artisan controller:make [Name]Controller

On Laravel 5, the command has changed:

在 Laravel 5 上,命令已更改:

php artisan make:controller [Name]Controller

Note:[Name] name of controller

注:【名称】控制器名称

回答by Jeffrey

Make resource controllerwith Model.

使用Model制作资源控制器

php artisan make:controller PostController --model=Post

php artisan make:controller PostController --model=Post

回答by bipin patel

For generate Model , controller with resources and migration best command is:

对于生成模型,具有资源和迁移的控制器的最佳命令是:

php artisan make:model ModelName -m -cr 

回答by Kamran

laravel artisan does not support default model and view generation. check this provider https://github.com/JeffreyWay/Laravel-4-Generatorsto generate models, views, seeder etc.

laravel artisan 不支持默认模型和视图生成。检查此提供程序https://github.com/JeffreyWay/Laravel-4-Generators以生成模型、视图、播种机等。

回答by aiswarya

You can make a plain controller file like

您可以制作一个普通的控制器文件,例如

php artisan make:controller --plain <controller name>

回答by Giovanny Gonzalez

Models:

楷模:

php artisan krlove:generate:model Videos --table-name=videos

回答by Abu Sufian

Create with Resource Method

使用资源方法创建

php artisan make:controller --resource ControllerName  --model=ModelName

Use It With a path

与路径一起使用

php artisan make:controller --resource path/ControllerName  --model=ModelName

回答by SouvikBiswas

Make model , Controller by

制作模型,控制器

php artisan make:model Customer -mc

Make model , Controller with Resource

制作模型,带资源的控制器

php artisan make:model Customer -mcr