生成控制器和模型

Sop*_*phy 28 php laravel

我是Laravel的新手,我在laravel 4(Beta版)附近玩.我想知道如何通过命令行使用生成Controller和Model php artisan.但我不知道该怎么做.

Bar*_*vdh 37

观看此视频:http://youtu.be/AjQ5e9TOZVk?t = 1m45s 您可以php artisan list查看所有命令,生成REST-ful控制器的命令是controller:make 您可以通过以下方式查看用法:php artisan help make:controller

  • 将在Laravel 5:https://github.com/laravel/framework/commit/cb1142897be11c59b374340fa0826408b13b9f55 php artisan make:model (2认同)

Dut*_*IFF 35

Laravel 5

其他答案对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
Run Code Online (Sandbox Code Playgroud)

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

运行php artisan help make:item以查看可以传递的内容.例如php artisan help make:migration,我们需要传递迁移名称,但我们也可以传递它--create=""--table=""指定要分别创建或修改的表名.运行php artisan make:migration create_articles_table --create="articles"以生成文章表.此外,生成模型负责为该模型生成迁移.遵循命名约定,它将被复数用于迁移.


Sop*_*phy 24

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

php artisan controller:make [Name]Controller
Run Code Online (Sandbox Code Playgroud)

在Laravel 5上,命令已更改:

php artisan make:controller [Name]Controller
Run Code Online (Sandbox Code Playgroud)

注意: [名称]控制器名称


Jef*_*rey 9

Model建立资源控制器.

php artisan make:controller PostController --model=Post


Kam*_*ran 6

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


bip*_*tel 5

对于generate Model,具有资源和迁移的最佳控制器是:

php artisan make:model ModelName -m -cr 
Run Code Online (Sandbox Code Playgroud)


小智 5

制作模型、控制器

php artisan make:model Customer -mc
Run Code Online (Sandbox Code Playgroud)

制作模型、控制器和资源

php artisan make:model Customer -mcr
Run Code Online (Sandbox Code Playgroud)