Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data from Pivot table?

I tried to get data from pivot table as:

@foreach ($announcements as $index => $item)
      {{dd($item->pivot->category->translate('en')->name)}}
      {{dd($item->pivot->category->name)}}
@endforeach

I attached screenshot:

enter image description here

like image 826
SFSFSFSF Avatar asked Jul 11 '26 09:07

SFSFSFSF


1 Answers

You shouldnot mention the model name:

{{dd($item->pivot->name)}}

if items and categories has a pivot table item_category with attribute name then, {{dd($item->pivot->name)}} gives the value of name attribute

like image 191
Sanzeeb Aryal Avatar answered Jul 13 '26 23:07

Sanzeeb Aryal