Calling Artisan commands via URL

Yusuf Abid
Feb 25, 2023

--

artisan command laravel

Sometimes we need to call artisan commands via url, because we’ve some limitations in our server mostly for developers that hosted the app on hosting server.

Let’s do it

Add this code to your ./routes/web.php

Route::get('artisan/{query}', function ($query) {
Artisan::call($query);
$output = Artisan::output();
return $output;
});

Now you can call artisan commands by this url:

http://127.0.0.1:8000/artisan/migrate:fresh

Above code same as “php artisan migrate:fresh” in terminal.

Enjoy!

--

--