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.
See this video: http://youtu.be/AjQ5e9TOZVk?t=1m45s
You can do
php artisan list to view all commands,
The command for generating REST-ful controllers is
You can view the usage with:
php artisan help make:controller
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 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.
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
--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.
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
Make resource controller with Model.
php artisan make:controller PostController --model=Post
For generate Model , controller with resources and migration best command is:
php artisan make:model ModelName -m -cr
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.
You can make a plain controller file like
php artisan make:controller --plain <controller name>
php artisan krlove:generate:model Videos --table-name=videos
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 model , Controller by
php artisan make:model Customer -mc
Make model , Controller with Resource
php artisan make:model Customer -mcr