How to execute artisan commands from route or controller in Laravel ?

By Hardik Savani | February 12, 2017 | | 49476 Viewer | Category : Laravel


Sometimes we require to run php artisan command from route or controller file in out Laravel Application, However we can do it using Artisan facade. Laravel Artisan facade that way we can easily run all artisan command with argument.

Artisan facade have two method call() and queue(), queue() through we can simply make process in queue like email sending etc. So let's see simple example with route. In this example we run "php artisan migrate" command using artisan facade. Here i bellow example you can learn how you can run artisan commands from route.

Example:

Route::get('command', function () {

/* php artisan migrate */

\Artisan::call('migrate');

dd("Done");

});

I hope it can help you...



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
***Do you want me hire for your Project Work? Then Contact US.


We are Recommending you: