Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Controller and Model

Tags:

php

laravel

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.

like image 837
Sophy Avatar asked Jan 10 '13 19:01

Sophy


People also ask

What creates a controller in Laravel by CMD?

we will use php artisan make controller command to create controller in laravel 6, laravel 7, laravel 8 and laravel 9 project. You have to see this tutorial for creating controller in laravel using artisan command. you can easily create controller with windows cmd and terminal.


2 Answers

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 controller:make You can view the usage with: php artisan help make:controller

like image 160
Barryvdh Avatar answered Oct 05 '22 04:10

Barryvdh


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.

like image 35
DutGRIFF Avatar answered Oct 05 '22 06:10

DutGRIFF