Launch Artisan command from anywhere

If you have an Artisan command, you can launch it not only from Terminal, but also from anywhere in your code, with parameters. Use Artisan::call() method:

1Route::get('/foo', function () {
2 $exitCode = Artisan::call('email:send', [
3 'user' => 1, '--queue' => 'default'
4 ]);
5 
6 //
7});

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord