Reputation: 1626
I am implementing redis backed queues but all of a sudden facing the above issue. Looks like $connection
variable is empty when it is passed to the Horizon.php. clearing route and config cannot be done because any artisan commands ends up throwing the same error. Below is the code in Horizon.php
. I did dd($connection)
and found it is empty.
public static function use($connection)
{
if (! is_null($config = config("database.redis.clusters.{$connection}.0"))) {
config(["database.redis.{$connection}" => $config]);
} elseif (is_null($config) && is_null($config = config("database.redis.{$connection}"))) {
throw new Exception("Redis connection [{$connection}] has not been configured.");
}
config(['database.redis.horizon' => array_merge($config, [
'options' => ['prefix' => config('horizon.prefix') ?: 'horizon:'],
])]);
}
Upvotes: 3
Views: 7427
Reputation: 18833
In my case I experienced a similar issue where we were named our connection something different besides "default" so we got the error:
Redis connection [default] has not been configured.
As of Laravel Horizon version 3 the installation process looks at the config option for horizon.use
within vendor/laravel/horizon/src/HorizonServiceProvider.php:
/**
* Setup the configuration for Horizon.
*
* @return void
*/
protected function configure()
{
$this->mergeConfigFrom(
__DIR__.'/../config/horizon.php', 'horizon'
);
Horizon::use(config('horizon.use', 'default'));
}
So in my case to resolve it I added a new Horizon config file to config/horizon.php, swapped out the "default" connection name for our connection name and then ran composer install for Horizon. It worked perfectly, just needed a value for config('horizon.use')
.
Upvotes: 0
Reputation: 411
The issue happened because of configuration caching in my case, as I mintioned in the old answer. However, Instead of editing vendor files, a better approach is to head to bootstrap/cache/config.php
, delete it or better rename to rollback if an issue happens. This will disable the configuration caching. Hence, running composer install or composer dump-autoload will not produce the error.
You can cache the configurations after that by running php artisan config:cache
I came across the same issue. My resolution, however, was a bit hacky and not very clean. But with a limited experience with Laravel that was the best I could come up with.
The problem in my case was caching configurations with php artisan config:cache
.
When checking for connenction the package uses this peace of code:
/**
* Setup the configuration for Horizon.
*
* @return void
*/
protected function configure()
{
$this->mergeConfigFrom(
__DIR__.'/../config/horizon.php', 'horizon'
);
Horizon::use(config('horizon.use'));
}
This function checks for a flag configurationIsCached
. If it is on, it just cancels merging the config from horizon and in turns, config('horizon.use')
will return null
.
Although I don't like it much, it solved the issue for me. What I have done is,
Took the config in horizon package vendor/laravel/horizon/config/horizon.php
and added it to my config directory config/horizon.php
.
In Illuminate\Support\ServiceProvider::mergeConfigFrom
, I temporarily commented out the condition checking for app caching. I guess there must be a better solution by maybe setting the variable to false.
run php artisan config:cache
.
remove the comment in Illuminate\Support\ServiceProvider::mergeConfigFrom
.
run php artisan horizon:install
.
and so it worked. I hope this helps.
Upvotes: 4