[英]Passing variables from one controller to another with laravel
Is it possible when redirect from one controller to another also to pass variables? 从一个控制器重定向到另一个控制器以传递变量时,是否可能? What I mean is that I have submit function and after submit I make redirect to url.
我的意思是,我有提交功能,提交后我将重定向到url。 Then in other controller trying to display some info based on variables.
然后在其他控制器中尝试显示基于变量的信息。 This is the redirect from first controller
这是来自第一个控制器的重定向
return Redirect::to('/cart/payment/order/' . $order->order_id . '+' . $order->user_id);
then in second controller this 然后在第二个控制器中
public function paymentView() {
$order = Order::where('order_id', $orderId)->first();
if (!$order) {
App::abort(404);
}
$userID = $order['user_id'];
$orderID = $order['order_id'];
}
Question is how to get $user_id
and $order_id
now? 问题是如何立即获取
$user_id
和$order_id
?
First your route declaration should accept them, something like this, depending on your route: 首先,您的路线声明应接受它们,具体取决于您的路线:
Route::get('cart/payment/order/{orderID}/{userID}'...
Then Laravel will automatically inject them in your controller method: 然后Laravel将自动将它们注入到您的控制器方法中:
public function paymentView( $orderID, $userID, ) {
And I recommend your URL to be with slash not with plus sign: 并且我建议您的网址使用斜杠而不是加号:
return Redirect::to('/cart/payment/order/' . $order->order_id . '/' . $order->user_id);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.