How to redirect to the requested page after login?

lckamal - 1 month ago

There is a link to the page which can be accessed by logged user only. When clicking on the link user will be redirected to /login page. After login user doesn't redirect to home or the previous page. It stays to /login itself.

Is there some workaround like pyrocms 2? in 2 we could send login/url/to/redirect

ryanthompson - 1 month ago

You can implement something like this: https://github.com/anomalylabs/users-module/blob/master/resources/views/login.twig#L5

This is the default users login page behavior. Might wrap that in an if.. cause if we don't set redirect here it will use the intended redirect (where you were booted from in the first place). So that view may need improvement.

lckamal - 1 month ago

added redirect as query string and worked.

if(!Auth::user()){
           redirect('/login?redirect='.url()->previous())->send();
       }