php artisan route:cache;
Horizon::auth(function ($request) {
dd('test');
});
My guess is that you're putting Horizon::auth() in your routes.php, routes/web.php or similar?
You may just as well call the function from for example App\Providers\AuthServiceProvider::boot() or similar; then the routes should still get cached, but Horizon::auth would still be called when trying to access the dashboard.
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
// Setup Horizon access
\Horizon::auth(function ($request) {
return $request->user()->is_admin;
});
}
The above didn't work for me, but did lead me to this which works:
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
Horizon::auth(function($request) {
return true;
});
}
Then make sure you put it behind a middleware, mine is ['web', 'auth', 'verified'] but you can create one for Horizon.
I can now php artisan route:cache and works fine. 🤷♂️
Most helpful comment
My guess is that you're putting
Horizon::auth()in yourroutes.php,routes/web.phpor similar?You may just as well call the function from for example
App\Providers\AuthServiceProvider::boot()or similar; then the routes should still get cached, butHorizon::authwould still be called when trying to access the dashboard.