gpt4 book ai didi

php - Laravel : Redirect the user to the same page after login

转载 作者:行者123 更新时间:2023-12-03 19:34:45 26 4
gpt4 key购买 nike

我有一个购物车产品页面,如果一个人点击产品添加到购物车按钮,他们将被重定向到登录页面。

成功登录后,我需要再次将用户发送回相同的产品页面。

我在登录 Controller 中使用了以下方式。

但它实际上并没有按照我想要的方式工作。
意味着它再次重定向到索引页面,我使用了return redirect()->back();也..但不能解决问题

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('/');
}
}

如何解决问题?

最佳答案

在这种情况下 back()intended()不管用。

您可以将最后一个产品页面保存到 session 中。非常简单的例子:

session(['last_product_page_id' => $product->id]);

然后在登录后使用此数据重定向用户:
if (session()->has('last_product_page_id')) {
return redirect()->route('product', session('last_product_page_id'));
}

关于php - Laravel : Redirect the user to the same page after login,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43204632/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com