Create CRUD module in just single command,with no need to import packages etc.
At EasyLaravel ,we have came up with amazing idea to make laravel developers life little bit easier.We have created single command that will create CRUD module with forms controller and much more.
With one command you will get :
- Migration created by the name you specify
- Model with same name of module in singular form as we make at laravel
- Controller with functions created -
- Index
- Create
- Store
- Edit
- Update
- Delete
Steps to make this thing possible -
Step 1 - Create new project
Create new laravel 5.3 project - usingcomposer create-project laravel/laravel Crud
Step 2- Download file from this link - Click here
Once downloaded copy and paste the file in App\Consoles\Commands directory
Step 3- Open App\Console\Commands\Kernel.php file
Opern Kernel.php file and Register your command ,here is code -
protected $commands = [
//
Commands\CRUDCommand::class
];
Step 4- Run php artisan command and check whether make:crud command is generated .
Step 5 -Before running command,lets take a look at what parameters the command accepts
php artisan make:crud Module_name --table=table_name --model=Model_name --fields=Form field that are created in views
Eg-
php artisan make:crud posts --table=posts --model=Post --fields=name,email,mobilenumber
Above command accepts parameters as follows
- posts= module name you want to give
- --table=Table name - which creates migration with table name defined
- --model= Name of model you want to create
- --fields= list of field separated by ' , ', this fields are automatically created in views
Note :
- Routes are create in routes\web.php
- Controller as - Module-Name\BaseController.php in controller directory
Now lets see what happens when we run this command
php artisan make:crud posts --table=posts --model=Post --fields=name,email,mobilenumber
Future Enhancement
- Add code in controller for all functions
- Creating Model with table name in it
- Perfect documentation
What's missing
We have created this CrudCommand for laravel 5.3 application only. If you want to implement in laravel 5.2 or previous version then change the path of routes file where file contents are appended .