Custom Artisan Commands in Laravel — a practical guide to Laravel custom artisan command with clear examples you can reuse in real projects.
Laravel Tutorial Series (26/27). Prefer one page? Read the complete Laravel tutorial (all 27 topics).
Short description
Artisan commands automate repetitive tasks from the CLI and can be scheduled with the Laravel scheduler.
Create a command
php artisan make:command SendWeeklyReport
protected $signature = 'report:weekly {--email=}';
protected $description = 'Send the weekly report';
public function handle(): int
{
$email = $this->option('email') ?: config('mail.from.address');
$this->info("Sending weekly report to {$email}");
// Report logic...
$this->info('Done');
return self::SUCCESS;
}
Run it
php artisan report:weekly --email=admin@example.com
Schedule it (`routes/console.php` or kernel schedule)
Schedule::command('report:weekly')->weeklyOn(1, '9:00');