walid mahmoud

21 Feb 2022

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

21 Feb 2022

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.

© 2024 Copyrights reserved for web-brackets.com