背景: 我在做什麼是我做了一個頁面顯示與複選框的參加者和事件的表。它一直在工作,直到我試圖通過屬於許多關係的透視表查詢我的複選框。laravel檢查數據透視返回錯誤包含()非對象
我已經看過一些其他線程,並嘗試使用相同的方法來檢查現有條目數據的支點。我正在使用contains()函數來查看我的與會者和scheduled_program_segment是否匹配,但出於某種原因,我的代碼得到了此錯誤。
問題:
我得到的錯誤Call to member function contains() on a non-object
。
這裏是我的代碼,我想有點是培訓相關
@foreach(Auth::user()->attendee as $attendee)
<td class="col-lg-1">
{{
Form::checkbox(
($program->name . $attendee->first_name),
'1',
$attendee->scheduled_program_segments->contains($attendee->id)
)
}}
我試圖改變到$與會者爲好。同樣的錯誤。
此外,當我運行
{{$attendee->scheduled_program_segments()->get()}}
我得到它我假設意味着我有透視表和模型建立正確的追隨者,但是它不工作,所以也許我錯了這裏。
[{"id":"1","created_at":"2014-11-14 15:19:44","updated_at":"2014-11-14 15:19:44","name":"Minecraft","description":"","date":"2014-11-06","cost":"20.00","start_time":"16:30:00","end_time":"17:30:00","location":"Cookstown","scheduled_program_id":"1","program_segment_id":"1","pivot":{"attendee_id":"1","scheduled_program_segment_id":"1"}},{"id":"1","created_at":"2014-11-14 15:19:44","updated_at":"2014-11-14 15:19:44","name":"Minecraft","description":"","date":"2014-11-06","cost":"20.00","start_time":"16:30:00","end_time":"17:30:00","location":"Cookstown","scheduled_program_id":"1","program_segment_id":"1","pivot":{"attendee_id":"1","scheduled_program_segment_id":"1"}}]
請你用你的模型更新你的問題?特別是Attendee班。 – lukasgeiter 2014-11-14 21:08:58