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

tkd5041's avatar

How To Pass A Simple Value To A View

I want to pass a simple sum of a column to my view.

I have my controller that grabs the items a person won in an auction. I then sum the total due. I then pass it to the view, but all I get is an error and it seems like it should be silly simple, but my brain is broken today.

My Controller

public function stripe()
    {
        $user = Auth::user();
        $items = Item::where('event_id', session('selected_event'))
                     ->where('current_bidder', $user->id)
                     ->where('sold', 1)
                     ->get();

        $total = Item::where('event_id', session('selected_event'))
                     ->where('current_bidder', $user->id)
                     ->where('sold', 1)
                     ->sum('current_bid');

        
        //dd($items, $total);
        return view('stripe/stripe', ['items' => $items, $total]);
    }

My Die and Dump

The value '115' is the correct sum.

 Illuminate\Database\Eloquent\Collection {#1308 ▼
 #items: array:2 [▶]
}
"115"

My blade code.

<div class="card-footer">
     <h5>Total Amount Due: ${{ $total }}.00</h5>
</div>
0 likes
2 replies
AdamT's avatar
AdamT
Best Answer
Level 9

You need to give total a key:

return view('stripe/stripe', ['items' => $items, 'total' => $total]);

Cheers, Adam

1 like
tkd5041's avatar

This was literally what I had originally written but then it kept giving me an error when used it on the page! Now I did it again and it worked beautifully! I am thankful for your reply!!!

1 like

Please or to participate in this conversation.