In this blog post, I'll help you set up a new Console command in Laravel to let you clear failed jobs in Laravel Horizon completely.

1. Create a New Command: Start by creating a new Laravel console command:

php artisan make:command FlushRedis --command=flush:redis

2. Add the Necessary Use Statement: In your newly created command, add the following use statement:

use Illuminate\Support\Facades\Redis;
Important: Ensure you don't add use Redis; directly in the command file. Doing so will lead to errors as it can't be called statically.

3. Update the handle() Method: In the handle() method of your command, add the following line:

Redis::command('flushdb');

4. Register the Command: Now, you need to register this command. Open App\Console\Kernel.php and add the command to the $commands array:

protected $commands = [
	...
	'\App\Console\Commands\FlushRedis',
];

5. Run the Command: With everything set up, you can now run the following command to clear all the jobs from Redis (and Horizon):

php artisan flush:redis

That's it!

Happy coding!

How to Clear Failed Jobs in Laravel Horizon: A Step-by-Step Guide