user image

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

How to check Laravel version?
Publish date: 2022-04-07 | Comments: 2
Method Illuminate\Auth\RequestGuard::attempt does not exist.
Publish date: 2022-02-18 | Comments: 2
What's the best approach to use Elasticsearch with Larave?
Publish date: 2022-02-21 | Comments: 2
How can I validate recaptcha in Livewire class ??
Publish date: 2022-02-23 | Comments: 2
tymon/jwt-auth 0.5.12 requires illuminate/support ~5.0
Publish date: 2022-02-18 | Comments: 2