I have a cart products page, if a person clicks on a product add to cart button they will be redirected to the login page.
After a successful login, I need to send the user back to same products page again.
I used the following way in login controller.
But it's not actually working the way i want.
Means it redirect to the index page again, I have used the return redirect()->back(); also..but doesn't solve the problem
if (auth()->attempt(array('email' => $request->input('email'),
'password' => $request->input('password')))){
if(Auth::user()->name == 'Admin'){
return redirect()->to('home');
}
else{
// return redirect()->back();
return redirect()->intended('/');
}
}
How to solve the issue?
In this case back() and intended() will not work.
You can save last product page to the session. Very simplified example:
session(['last_product_page_id' => $product->id]);
And then use this data to redirect user after login:
if (session()->has('last_product_page_id')) {
return redirect()->route('product', session('last_product_page_id'));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With