0

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. 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?

1 Answer 1

1

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:

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);

Sign up to request clarification or add additional context in comments.

3 Comments

Ok, I've made changes as you suggest me but I've got production.ERROR: exception 'ErrorException' with message 'Undefined variable: orderId'... when I trying to query here ` $order = Order::where('order_id', $orderId)->first();`
@JordanVit make sure the variable name in the route and in the controller method is matching the one you use in the where clause.
Yes, it was orderID instead of orderId. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.