๐ŸŸ A package to execute a random artisan command original

by Freek Van der Herten โ€“ 1 minute read

Aren't you tired of having to think about which artisan command to execute? The spatie/laravel-random-command package takes that pain away. It provides a random command that will pick a random command and execute it.

This is how you can unleash the power of the random command. Just execute it and don't look back!

php artisan random

Let's take a look at how such greatness is achieved. Here's the code of the RandomCommand.

public function handle()
{
     $this->confirm('You are about to execute a random command. Are you sure you want to do this?');

    $allCommands = $this->getApplication()->all();
  
    $commandString = collect($allCommands)->keys()->random();
  		
    $this->info("Executing command: `{$commandString}`");

    // ๐Ÿงจ๐Ÿงจ๐Ÿงจ
    Artisan::call($commandString, [], $this->output);
}

We don't recommend installing this in your production environment. Or your local environment. In fact it might be best not to install it at all.

Join 9,500+ smart developers

Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

No spam. Unsubscribe anytime. You can also follow me on X.

Found something interesting to share? Submit a link to the community section.