0
這是有點複雜,但無論.. 好吧,我有四個表選擇記錄取決於兩個ID
1-Projects
id | int 11
name
2-Sections
id | int 11
project_id | int 11
name
3-Users
id | int 11
4-User_Section_project (this table is used to assign users to sections they will work on in the project
id | int 11
project_id | int 11
section_id | int 11
user_id | int 11
反正是有使用ORM作出類似的東西的工作,我只獲得分配的部分
$sections = $user->projects()->sections()
我做它在我的用戶模型中使用下面的代碼
public function workshops()
{
return $this->belongsToMany('section', 'user_project_section', 'user_id', 'section_id')->whereIn('user_project_section.project_id', array(1,2,3));
}
,我把它像
@foreach ($user->sections as $section)
{{$section->name}}
@endforeach
該代碼會得到相關的章節中項目1,2,3用戶。 如果我想使它爲一個指定的項目,我通過一個參數問題是當添加圓括號()在函數的調用視圖中它不起作用,所以我不能傳遞一個參數
@foreach ($user->sections() as $section)
{{$section->name}}
@endforeach
@foreach ($user->sections() as $section)
{{$section->name}}
@endforeach
是什麼讓它變得更糟沒有錯誤消息彈出和監控我的Mysql服務器查詢,根本不查詢(執行)。 我真的需要通過一個參數 更多信息: 使用Print_r似乎沒有()它返回集合對象,它會返回BelongsToMany對象。
我已經知道了,我使用雄辯,我只是想知道是否有人會提供一些提示。 任何方式,我做出來 –