zaster
7 months ago

Trying to get property 'cost_item' of non-object

Posted 7 months ago by zaster

POController.php

     $pos = PO::all();
     $pos->load(['po_items.cost_item.vendor_company']);
     //dd($pos);

po.blade.php

 @foreach ($pos as $po)                      
                  <tr>
                    <td>{{$po->id}}</td>
                    <td>{{$po->date}}</td>
                    <td>{{$po->po_item->cost_item->vendor_company->id}}</td>
..
..
@endforeach

dd($pos) shows all the collections with relations without any issue

but when i try to view this page. I am getting this error

Trying to get property 'cost_item' of non-object

Relationships are as below mentioned

po hasMany po_items

po_item belongsTo cost_item

cost_item belongsTo vendor_company

Please sign in or create an account to participate in this conversation.