spatie/laravel-random-command
Adds a playful php artisan random command that picks and runs a random Artisan command for you. Also auto-schedules itself to run at random times. Mostly for fun—probably not something you want in production (or anywhere).
random) without modifying core Laravel workflows, making it ideal for environments where ad-hoc command execution is desired (e.g., CI/CD, local development, or maintenance scripts).app/Console/Kernel.php.migrate:fresh in production). Requires explicit whitelisting/blacklisting.queue:work or schedule:run)?php artisan random --env=testing).cache:clear or optimize:clear).composer require spatie/laravel-random-command
php artisan vendor:publish --provider="Spatie\RandomCommand\RandomCommandServiceProvider"
app/Console/Kernel.php to filter commands (e.g., exclude migrate).protected function commands()
{
$this->load(__DIR__.'/Commands');
// Exclude sensitive commands
$this->excludeCommands(['migrate', 'db:wipe']);
}
php artisan random # Executes a random registered command
php artisan random --limit=3 # Run 3 random commands sequentially
Kernel.php to be eligible for randomization.--env flag to target specific environments (e.g., php artisan random --env=staging).parallel-laravel packages.queue:work requires a queue connection). Validate dependencies upfront.--dry-run flags where possible.README.md.php artisan random --verbose
CONTRIBUTING.md section for custom randomization logic (e.g., weighted commands).// Example: QueueRandomCommand.php
public function handle()
{
$command = $this->getRandomCommand();
Command::dispatch($command);
}
| Failure Scenario | Mitigation |
|---|---|
| Destructive command executed | Whitelist-safe commands; use --dry-run. |
| Command dependencies fail | Validate prerequisites (e.g., DB connections). |
| Infinite loops (e.g., recursive commands) | Set a max execution limit (--limit). |
| Command not found | Ensure all commands are registered in Kernel.php. |
How can I help you explore Laravel packages today?