
[英]How to prevent lost session value in laravel 5.2 when redirect from any controller to another controller?
[英]How can I redirect from a controller with a value to another controller in laravel?
OrderController.php
if (request('payment_method') == 'online') {
return redirect(route('payments.pay', $order->id));
}
web.php
Route::POST('/pay/{orderId}', 'PublicSslCommerzPaymentController@index')->name('payments.pay');
PublicSslCommerzPaymentController.php
session_start();
class PublicSslCommerzPaymentController extends Controller
{
public function index(Request $request, $ordId)
{
//code...
}
}
在索引 function 中,我需要来自 OrderController 的订单 ID。
But the Error I am getting
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException 此路由不支持 GET 方法。 支持的方法:POST。
如果你想重定向到命名路由,你可以使用这个:
return redirect()->route('payments.pay', ['orderId' => $order->id]);
如果你想生成重定向到 controller 动作,你可以试试这个:
return redirect()->action(
'PublicSslCommerzPaymentController@index', ['ordId' => $order->id]]
);
只需将 web.php 从POST方法更改为GET方法
像这样的东西
Route::GET('/pay/{orderId}', 'PublicSslCommerzPaymentController@index')->name('payments.pay');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.