【发布时间】:2019-03-06 16:27:10
【问题描述】:
在 laravel 5.7 中,会话在重定向到另一个页面后消失。 我正在开发一个应用程序,在该应用程序中,我将用户推送到支付网关页面,在该页面之前,我根据 laravel documentation 将数据存储在会话中。从支付网关返回后,当我尝试检索该会话时,它返回空。 谁能告诉我如何解决这个问题。
我的代码是这样的
public function processPayment(Request $request)
{
//...........
session()->put('order_checkout_data', [
'gateway' => 'paypal',
'data' => $paypalData
]);
//$request->session()->save(); <!-- This i tried after reading some solution but didnt help
//print_r(session('order_checkout_data')) <!-- I can see the session here
$paypal = new PayPal();
$response = $paypal->purchase($paypalData);
if ($response->isRedirect()) {
$response->redirect(); //This is where redireting to paypal
}
}
public function handleGatewayResponse(Request $request){
print_r(session('order_checkout_data')); //No data
}
我也尝试了会话全局函数和外观,就像这些
Session::put('order_checkout_data', [
'gateway' => 'paypal',
'data' => $paypalData
])
还有
session(['order_checkout_data'=>[
'gateway' => 'paypal',
'data' => $paypalData
]])
但没有价值。 我的环境设置喜欢这样
SESSION_DRIVER=file
SESSION_LIFETIME=360
我尝试浏览一些有类似问题的链接,但没有帮助。以下是我关注的链接:
【问题讨论】:
-
handleGatewayResponse方法是否被 PayPal 服务器调用?如果是这样,您的会话为空是正常的,因为它们是 2 个不同的客户(一个是用户,另一个是 PayPal) -
handleGatewayResponse是处理支付成功后PayPal网关重定向的响应的函数。但我仍然认为会话应该与应用程序一起存在,对吗?因为它不是flash session。 -
您能否将
$response->redirect();中的代码添加到您的问题中并尝试return $response->redirect(); -
你可以试试这样的:return redirect()->route('your route', $response);
-
@Remul
$response->redirect();是paypal封装SDK的方法。这是网关默认功能。我正在使用这个包github.com/thephpleague/omnipay
标签: php laravel laravel-5 laravel-5.2 laravel-5.1