When one logout redirect isn’t enough.

Our application has several different “sites,” which need various degrees of customization, although they all use mostly the same flow for our application. One area of customization is the login page. If they’re associated with our generic site, they would go to ourapp.com/generic and see the login. If they just go to ourapp.com, they get a different view. The challenge is that, on logging out, Laravel by default just redirects everybody to the same page.

I found this SO post that was close, but (perhaps because a 5.2 change?) it wasn’t quite working. Instead, this code works for me:

public function logout() {
    $redirect = (Auth::user()->site->loginPage()) ? Auth::user()->site->loginPage() : '/';
    Auth::guard($this->getGuard())->logout();
    return redirect($redirect);
}

I actually had to spend some time building a settings model for site settings, since we hadn’t had to use those before. I’d just built them manually, so today I’m going to work on building out some views so that they can be user-editable.

Leave a Reply

Your email address will not be published. Required fields are marked *