In Ploi, it is possible to show the Laravel Horizon statistics and failed jobs for your application. This makes it easy and fast to see what is going on in your Laravel Horizon installation.
Not only that, but it also allows you to interact with the Ploi API to get your Horizon data so you can use these details in your own software.
Setting this up requires a few tweaks to your HorizonServiceProvider.php and config/cors.php file.
First, let's start with the cors.php file, make sure to include horizon/*:
return [ 'paths' => ['horizon/*'], // ... ];
Next, consider the following code in this file app/Providers/HorizonServiceProvider.php:
protected function gate() { Gate::define('viewHorizon', function ($user) { return in_array($user->email, [ // ]); }); }
We're going to make some adjustments to make it work so you can connect remotely. Change this code to this:
protected function gate() { Gate::define('viewHorizon', function ($user = null) { if(request()->bearerToken() && request()->bearerToken() === config('services.horizon.token')){ return true; } // Continue with your own original logic here }); }
Take note: The $user variable inside the function closure is now made nullable.
Next in your config/services.php file add the following block:
'horizon' => [ 'token' => env('HORIZON_TOKEN') ]
And fill in the HORIZON_TOKEN inside your .env file, you can make this any random token you'd like, as long as you save it because we'll need to enter this token inside Ploi.
Next, we're going to configure your site inside Ploi to make it all work and come together.
Head over to your site in Ploi and visit the Laravel, then the settings tab. In here, fill in the endpoint and the authorization token you've entered earlier:
After this, the Horizon tab will pop up and you'll be able to view your statistics. We'll also display a Laravel Horizon card below the deployments card in the General tab so you have quick and easy access to the latest statistics.
If you want, you can also integrate this into your own project by using the Ploi API. We've created an endpoint to gather these statistics. More information on that here: https://developers.ploi.io/sites/laravel-horizon-statistics