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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s