2017-03-05 126 views
3

我試圖從透視表中獲取數據:如何從數據透視表中獲取數據?

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

我附截圖:

enter image description here

+0

這是否幫助您http://stackoverflow.com/questions/27434338/laravel-get-pivot-data-for-specific-many-to-many-relation –

+0

發生什麼了? –

回答

1

您shouldnot提型號名稱:

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

如果itemscategories有一個數據透視表item_category,屬性爲name然後,{{dd($item->pivot->name)}}給出名稱屬性的值

相關問題