So let's say you visit the url http://example.com/admin/post/create but you need to be logged in to visit this page (The route has a middleware of auth). The middleware kicks in and redirects you to the login page. Now when you login you will be redirected to the intented page and that is /admin/post/create.
May 24, 2015
8
Level 8
Redirect Intended
Hi,
How do you manage the intended redirect with the existing authentication system Laravel provides out of the box?
The App\Http\Controllers\Auth\AuthController.php uses the AuthenticatesAndRegistersUsers trait.
The public function postLogin(Request $request) says:
...
if ($this->auth->attempt($credentials, $request->has('remember')))
{
return redirect()->intended($this->redirectPath());
}
...
I have a show method with:
if ( !$foo->is_free && !app('auth')->check()) {
return redirect('login');
}
When I perform the return redirect('login'); what do I need to provide to have the return redirect()->intended($this->redirectPath()); intended working?
Thank you.
Level 8
I found.
I needed to perform the following
return redirect()->guest('auth/login');
//or with my custom route:
return redirect()->guest('login');
Now the intended is working properly.
2 likes
Please or to participate in this conversation.