Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eggplantSword's avatar

Get info sent in session from one controller to another

I have a controller method that ends in two different redirects depending on the user role, all users except one create an order and the other one doesn't, I'm trying to send some information in the session to another controller to then send to a view.

This is what I have

public function cashOrder($amount, $products, $delivery)
{
    if (auth()->user()->role_id !== Role::JOKER) {
        DB::beginTransaction();
        //create order

        DB::commit();

        return redirect('cart/summary/' . $order->id);
    }

    $joker = collect();

    $joker->products = $products;

    $joker->client_id = auth()->user()->id;
    $joker->charge_id = 'no_charge_cash';
    $joker->charge_dateTime = date('Y-m-j H:m:s');
    $joker->charge_currency = 'cash';
    $joker->charge_amount = $amount;

    if ($delivery) {
        $joker->delivery_customer = $delivery['customer'];
        $joker->delivery_phone = $delivery['phone'];
        $joker->delivery_email = $delivery['email'];
    }

    return redirect('cart/joker_summary')->with('info', $joker);
}

I then have this route

 Route::get('cart/joker_summary', 'CartController@showJokerSummaryPage');

And this method in the other controller, if I dd($joker) after setting it I do see the info but it sends the variable joker as empty to the vue component.

    public function showJokerSummaryPage(Request $request) {
        $joker = $request->session()->get('info');

        return Inertia::render('Cart/JokerSummary', [
            'joker' => $joker
        ]);
    }

What am I doing wrong? or What is the correct way to do this?

0 likes
3 replies
Talinon's avatar

@msslgomez Why wouldn't you just handle the conditional return within the same controller?

// ......

if ($delivery) {
        $joker->delivery_customer = $delivery['customer'];
        $joker->delivery_phone = $delivery['phone'];
        $joker->delivery_email = $delivery['email'];
    }

//    return redirect('cart/joker_summary')->with('info', $joker);

return Inertia::render('Cart/JokerSummary', [
            'joker' => $joker
        ]);

eggplantSword's avatar

@talinon I did try that but I wanted a route in case something happened, but as long as it works I don't mind the route, this is for demonstrative purposes anyways. It's also sending $joker as empty if I do it this way

eggplantSword's avatar
eggplantSword
OP
Best Answer
Level 9

I changed $joker like this and that did the trick

$joker = collect([
            'products' => $products,
            'user' => auth()->user()->name,
            'status' => 'order_request',
            'client_id' => auth()->user()->id,
            'charge_id' => 'no_charge_cash',
            'charge_dateTime' => date('Y-m-j H:m:s'),
            'charge_currency' => 'cash',
            'charge_amount' => $amount,
            'delivery_customer' => $delivery['customer'],
            'delivery_phone' => $delivery['phone'],
            'delivery_email' => $delivery['email'],
        ]);

Please or to participate in this conversation.