redirect after login and logout


redirect after login and logout



I don't how how chang path to redirect my website after login and logout. In first example I found that I must change RedirectIfAuthenticated. But If I have


RedirectIfAuthenticated


public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect()->route('myroute');
}

return $next($request);
}



which doesn't redirect me when I want it to. And where can I change the redirect place after logout?





post your controller please.
– Adnan Mumtaz
Jul 2 at 6:40





Which controller?
– MrBelongsTo
Jul 2 at 7:17





Login controller
– Adnan Mumtaz
Jul 2 at 7:21




3 Answers
3



try to use


return redirect('your endpoint');



the detail implementation is depending on your controller/middleware





t doesn't work. earlier I was able to and I thought that i do it that. Itry remove every information about redirect from the function. I left only return $next($request); and it redirect me pasted.co/04172089 [code]
– MrBelongsTo
Jul 2 at 7:24






so there is a problem with the conditional if (Auth::guard($guard)->check()) or return redirect()->route('myroute');
– Rafid
Jul 2 at 7:27


if (Auth::guard($guard)->check())


return redirect()->route('myroute');





How I can solve this problem and why redirect me without redirect() into this middleware?
– MrBelongsTo
Jul 2 at 7:30





try to change return redirect()->route('myroute'); to return redirect('your endpoint');
– Rafid
Jul 2 at 7:32


return redirect()->route('myroute');


return redirect('your endpoint');





I tryed. But I don't understand why redirect works (but not to path what I want), if I remove any information of redirect from middleware.
– MrBelongsTo
Jul 2 at 7:49



first check weather you have asign the name of the routes? you try to redirect('myroute') but in your route file have you define this route or not? let you first check if not then define it.





This route exist. I change it's name for post needs
– MrBelongsTo
Jul 2 at 7:47




In app/Http/Controllers/Auth/LoginController.php


app/Http/Controllers/Auth/LoginController.php


protected $redirectTo = '/home'; // change it as you like






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to add background colour in existing image using Swift?

What's the difference between DDS and SOME/IP?

Moria Casán