Running All Laravel Artisan Commands via Route (Complete Guide)

Running All Laravel Artisan Commands via Route (Complete Guide)

Laravel Artisan is the command-line interface (CLI) that helps you manage, optimize, and automate your Laravel application.

This tutorial covers:

  • What Artisan is
  • Commonly used Artisan commands
  • Cache & optimization commands
  • Migration & database commands
  • Queue, schedule & storage commands

<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Artisan;

Route::get('/clear-cache', function () {
    Artisan::call('cache:clear');
    Artisan::call('route:clear');
    Artisan::call('config:clear');
    Artisan::call('config:cache');
    Artisan::call('view:clear');
    Artisan::call('storage:link');

    return "Cache cleared successfully!";
});