Avatar
SliceTech
  • 1 week ago
  • 2 min read

Run Artisan Commands via Route

Blog Image
Run Artisan Commands via Route

Sometimes during development, you need to quickly clear caches or set up symbolic links without manually running multiple Artisan commands. Here's a handy trick to execute common Artisan commands via a simple route in your Laravel application!

🔧 The Solution

Add this temporary route to your routes/web.php file:

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

    dd('Successfully ran Artisan commands!');
});

What This Does:

  • config:clear – Clears the configuration cache.
  • cache:clear – Flushes the application cache.
  • route:clear – Removes the route cache.
  • storage:link – Creates a symbolic link from public/storage to storage/app/public (useful for file storage).

After visiting /run in your browser, you'll see a success message confirming the commands ran successfully.

⚠️ Important Note

This route should only be used in local or staging environments for convenience. Never keep it in production as it poses a security risk—anyone could trigger these commands if the route is exposed.

Once you're done, remove the route to prevent unintended access.

💡 Why Use This?

  • Saves time by running multiple commands in one go.
  • Great for quick debugging when caches need clearing.
  • Helpful in shared environments where CLI access isn't always available.

Try it out and streamline your Laravel workflow!

Happy coding! 💻✨