0

I am trying to pass a value from the controller to my view, it keeps showing that the variable is not defined. how do i solve it ?

public function showItemPage(Order $order)
    {
        $products = Product::all();

        $items=$order->packages[0];

  
        $bidSessions = BidSession::find($items->bid_session_id)->get();
       

        return view('app.order.item', array('order' => $order,'products' => $products) , compact("bidSessions"));
    }

When log:info($bidSessions), it shows that I have the data.

{
   "id":1528,
   "page_id":1,
   "name":"Test Steven",
   "user_id":1,
   "channel":"facebook_live",
   "video_id":"486698512444605",
   "video_url":"https:\/\/www.facebook.com\/ricksmanfishmarket\/videos\/486698512444605\/",
   "data":{
      "standalone":"no"
   },
   "start_date":1621332720,
   "end_date":null,
   "ended_at":1621333018,
   "created_at":"1621332887",
   "updated_at":"1621333018",
   "deleted_at":null
}

but when I want to display it

<p> {{$bidSessions}} </p>

This errors shows up

enter image description here

Lee Soon Fatt
  • 167
  • 3
  • 15
  • 1
    You don't do `view(..., array(...), compact(...))`; that's 3 arguments to view, but it expects 2. This is a syntax typo; fix it as `return view('app.order.item', array('order' => $order, 'products' => $products, 'bidSessions' => $bidSessions));` or `return view('app.order.item', compact('order', 'products', 'bidSessions'));` – Tim Lewis May 31 '21 at 14:27
  • @TimLewis I did ``` return view('app.order.item', compact('order' ,'products', 'bidSessions'));``` , but still the same. thanks for the fast reply – Lee Soon Fatt May 31 '21 at 14:30
  • 2
    Your error screenshot is saying this error is on the `form` blade file, but your code is `app.order.item`, which would point to `resources/views/app/order/item.blade.php`, not `form.blade.php`... Are you sure this is the right spot you're fixing? – Tim Lewis May 31 '21 at 14:33
  • Does this answer your question? [How to pass data to view in Laravel?](https://stackoverflow.com/questions/18341792/how-to-pass-data-to-view-in-laravel) – miken32 May 31 '21 at 15:24

0 Answers0