Support the ongoing development of Laravel.io →
posted 5 years ago
Laravel

I experiment with artisan CLI Laravel 6.x, I went call a command from another command or put in a route in Laravel call programmatically???

\Laravel\code\project1\routes\web.php artisanac but getting ERRORS - how to use the lib of the Artisan (import)

Symfony\Component\Debug\Exception\FatalThrowableError Class 'App\Console\Commands\Artisan' not found

http://homestead.test/test-artisan

routes/web.php Route::get('test-artisan', function () { $exitCode = Artisan::call('email:send', [ 'user' => 'test', '--sendEmail' => true, ]); });

Last updated 3 years ago.
0

Hi, you can make this work.

Currently it doesn't because it cannot resolve the Artisan class, which is a facade. The full class name is 'Illuminate\Support\Facades\Artisan', but it's alias is 'Artisan'. Add a '\' in front of Artisan to make it global. That will use the alias.

Route::get('test-artisan', function () {
    $exitCode = \Artisan::call('email:send', [ 'user' => 'test', '--sendEmail' => true, ]);
 });

All aliases are listed in the config\app.php file.

Another way to solve this is to add using statements on top of the file.

use Artisan;
// OR
use Illuminate\Support\Facades\Artisan;
Last updated 5 years ago.

lse123 liked this reply

1

Thanks

Worked

I knew the solution but -- I did not know what use/import

You know any IDE that provides hints for Laravel... imports?

0

I'm glad I could help. Please mark the thread as solved.

Regarding the IDE I cannot suggest any. I myself find hinting in PHP not good enough. It just frustrates and slows me down. When I gained enough insight into Laravel I switched it off completely. As a sideeffect I started to read the source code and gained a deep understanding of what is going on behind the scenes.

lse123 liked this reply

1

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.