Reputation: 9275
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.
Upvotes: 46
Views: 232555
Reputation: 6579
You can do php artisan list
to view all commands,
The command for generating REST-ful controllers is controller:make
You can view the usage with: php artisan help make:controller
Upvotes: 53
Reputation: 149
You can generate controller and model individually and together also.
create Controller
php artisan make:controller Controllername
Create Model
php artisan make:model Modelname
Create controller and model together
php artisan make:controller Controllername --model=Modelname
Note: Please make habit to create controller and model name capitalize (First letter capital letter).
Upvotes: -1
Reputation: 378
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
Upvotes: -1
Reputation: 111
php artisan make:controller --resource Backend/API/DemoController --model=Demo
Upvotes: -1
Reputation: 53
Make model , Controller by
php artisan make:model Customer -mc
Make model , Controller with Resource
php artisan make:model Customer -mcr
Upvotes: 5
Reputation: 453
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
Upvotes: 0
Reputation: 9275
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
Upvotes: 35
Reputation: 2111
For generate Model , controller with resources and migration best command is:
php artisan make:model ModelName -m -cr
Upvotes: 13
Reputation: 2106
Make resource controller with Model.
php artisan make:controller PostController --model=Post
Upvotes: 18
Reputation: 809
Models:
php artisan krlove:generate:model Videos --table-name=videos
Upvotes: 1
Reputation: 567
You can make a plain controller file like
php artisan make:controller --plain <controller name>
Upvotes: 4
Reputation: 5223
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.
Upvotes: 38
Reputation: 2741
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.
Upvotes: 6