Sunday, 28 August 2016

Unknown

Part 1- Create command line apps using make:command laravel 5.3 at easylaravel

What is artisan ??

Artisan is commandline interface to create controller ,migration,model and also our own commands that will do specific task.Artisan provides list of commands

type : php artisan list

Create command ,follow steps -

  1. Create Command -
    Run composer and type - " php artisan make:command Say " ,
    command will be created in console/commands/Say.php
  2. Edit your command file and add logic that needs to be executed -
    In Say.php edit -
    1. Edit name and signature of the console command.edit -
      protected $signature = 'Say:hello {user}';
      {user} - command arguments
      eg- 'php artisan Say:hello Omkar'; ,here omkar is argument
    2. You can add dependencies inside constructor and laravel will take care of rest of it.
      protected $user;
      public function __construct(User $user) {
      parent::__construct();
      $this->user = $user;
      }
    3. Write command logic i.e the code that you want to execute when command runs in artisan
      public function handle()
      {
      $this->comment('Hello : '.$this->user);
      }
  3. Register command
    Register command in Console\kernel.php protected $commands = [ Commands\Say::class ];
  4. Run Command -
    php artisan Say:hello

Thank you, Part 2 will be posted soon.

Unknown

About Unknown -

Freelancer,Entrepreneur,Aesthetic bodybuilder.

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

Subscribe to this Blog via Email :