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

(This post was last modified: 01-25-2023, 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


Messages In This Thread
Customize the redirect if not logged in - by groovebird - 01-25-2023, 07:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB