walid mahmoud
Published in : 2022-02-21

Laravel redirect to the last location after login

Laravel

I use laravel 8 

I want to prevent users from commenting until logged in.

 my issue is to redirect to the last location after login

not to the home page.

Does anyone have an idea?

Comments

Yasen Sayed Date : 2022-02-21

Best answers

8

Best answers

8

Hi Walid, 

 

You should modify the LoginController.php and add these methods.

 

public function showLoginForm(){ session(['link' => url()->previous()]); return view('auth.login');}protected function authenticated(Request $request, $user){ return redirect(session('link'));}

I hope these help you.

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

Laravel Network is unreachable stream_socket_client 587
Publish date: 2022-02-16 | Comments: 4
Laravel clear cache files manually
Publish date: 2022-03-02 | Comments: 2
[solved] Class "App\Exceptions\Client" not found
Publish date: 2022-02-09 | Comments: 2