Skip to content

Instantly share code, notes, and snippets.

@uyab
Last active September 19, 2019 02:29
Show Gist options
  • Save uyab/ef29270844387c2f18ad1236fafac770 to your computer and use it in GitHub Desktop.
Save uyab/ef29270844387c2f18ad1236fafac770 to your computer and use it in GitHub Desktop.
Laravel command skeleton
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class SampleCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
* arg1 = required
* arg2 = optional
* arg3 = optional with default value
* Sample usage: php artisan sample:command foo bar baz --flag
*/
protected $signature = 'sample:command {arg1} {arg2?} {arg3=foo} {--flag}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('arg1 = '.$this->argument('arg1'));
$this->info('arg2 = '.$this->argument('arg2'));
$this->info('arg3 = '.$this->argument('arg3'));
if ($this->option('flag')) {
$this->info('With option --flag');
}
$this->info('sample info');
$this->warn('sample warning');
$this->error('sample error');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment