skip to Main Content

Laravel Call Artisan Command From Route Or Controller

Laravel call artisan command from route or controller


Laravel provides awesome artisan command functionality. using artisan command we can create the controller and model file or clear the blade file cache and many more. How we can call artisan command from controller or route.

Let’s see how we can call artisan command from route or controller. So we can easily call artisan command directly from URL. Laravel provides functionality for programmatically execute commands using Artisan::call¬†function.

So let’s see, How we can execute command programmatically. First of all, we are run the migration command using programmatically.

Route::get('command/migrate', function () {
    $exitCode = \Artisan::call('migrate');
    dd("Done");
});

Now, we run migration command using “command/migrate” URL. it’s too easy to run migration¬†command programmatically.

Now, Let’s see the example for clear blade cache programmatically

Route::get('command/clear/cache', function () {
    $exitCode = \Artisan::call('view:clear');
    dd("Done");
});

It’s too easy to execute the Laravel artisan command using programmatically route or controller.

If you face any issue write the comment below.

Saroj

I am a web designer and developer part-time blogger. Write something on some free time. Find my every day thought here :)

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top