Can laravel 5.5 horizon use controller method instead of closure?

Published 8 months ago by skeith22

I'm having problems handling the Horizon::auth() method in the routes. Can the method use a controller to handle the response?

the current code shows an error when you return false, but when you return true it's normal, it shows the horizon dashboard.

current code

Horizon::auth(function ($request) {
    if (TRUE) {
        return true;
    }

    return false;
});
bobbybouwmann

As far as I know you should do this check in a service provider and not in your controller. You should simply return true or false and that's it.

What are you trying to do exactly?

skeith22

@bobbybouwmann I wanted to control where it goes instead of returning false

bobbybouwmann

What do you mean with I wanted to control where it goes instead of returning false?

skeith22

@bobbybouwmann what I mean is instead of just false could like return redirect? or return a view?

Ruffles
Ruffles
6 months ago (294,740 XP)

That method is for authorization so only true or false is valid as return types, just like Form Requests and the authorize() method.

bobbybouwmann

Indeed, you can only return true or false there. You can do a redirect when you wrap everything in a middleware ;)

Please sign in or create an account to participate in this conversation.