Welcome Guest, Not a member yet? Register   Sign In
Customize the redirect if not logged in
#1

(This post was last modified: Yesterday, 08:08 AM by groovebird.)

Hi,

if the user is not logged in and calls a protected route then the redirect goes to the /login route. How can i change this route to a custom url?

Doing a check with

PHP Code:
if auth()->loggedIn() { //go to custom url} 

does not work in the controller. The redirect goes always to the /login route

I found the solution in the documentation by using a filter:

PHP Code:
class LoggedIn implements FilterInterface
{
    public function 
before(RequestInterface $request$arguments null)
    {

        if (!
auth()->loggedIn()) {
            return 
redirect()->to(site_url('mycustomurl'));
        }
    }

    public function 
after(RequestInterface $requestResponseInterface $response$arguments null)
    {

    }

Reply




Theme © iAndrew 2016 - Forum software by © MyBB