Sunday, 9 October 2016

Unknown

Create CRUD module in just single command,with no need to import package at Easylaravel

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 :

  1. Migration created by the name you specify
  2. Model with same name of module in singular form as we make at laravel
  3. Controller with functions created -
    1. Index
    2. Create
    3. Store
    4. Edit
    5. Update
    6. Delete

Steps to make this thing possible -

Step 1 - Create new project

Create new laravel 5.3 project - using
composer 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

  1. posts= module name you want to give
  2. --table=Table name - which creates migration with table name defined
  3. --model= Name of model you want to create
  4. --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

  1. Add code in controller for all functions
  2. Creating Model with table name in it
  3. 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 .

Thank You, If you have any doubts please comment .Like and share to make everyone life easier.

Unknown

About Unknown -

Freelancer,Entrepreneur,Aesthetic bodybuilder.

    Knows :
  • Laravel Framework
  • Ionic Framework + Angular JS
  • Bootstrap
  • CSS
  • Jquery

Subscribe to this Blog via Email :