[php] Generate Controller and Model

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.

This question is related to php laravel

The answer is


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

php artisan make:model ModelName -m -cr 

You can make a plain controller file like

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

Models:

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

See all Available Controller : You can do PHP artisan list to view all commands

For help: PHP artisan help make:controller

php artisan make:controller MyControllerName

enter image description here


Make model , Controller by

php artisan make:model Customer -mc

Make model , Controller with Resource

php artisan make:model Customer -mcr

Use:

make:model {{SingularName}}

e.g

make:model Video

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

php artisan controller:make [Name]Controller

On Laravel 5, the command has changed:

php artisan make:controller [Name]Controller

Note: [Name] name of controller


Laravel 5

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

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.

Run php artisan help make:item to see what you can pass it. For instance php artisan help make:migration shows 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.


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

Make resource controller with Model.

php artisan make:controller PostController --model=Post


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


php artisan make:controller --resource Backend/API/DemoController --model=Demo