我有admin
表,admin
有很多form
。每个form
都会分配到其信息中心显示的admin
。
问题是form
可能没有分配给任何admin
。
我希望得到所有forms
任何帮助表示赞赏。谢谢!
修改:Admin
通过自定义关系与form
相关Here
总结一下,
Admin.php
public function states(){
return $this->belongsToMany('App\State');
}
public function cities()
{
return $this->belongsToMany('App\City');
}
//gets the forms in this admin's city or state
//Let me know if there is a better way to do this, i feel like im overdoing stuff here
public function forms()
{
//cities
$cities = $this->cities->pluck('name');
//states
$states = $this->states->pluck('name');
$users = User::whereIn('state',$states)>orWhereIn('city',$cities)->get()->pluck('id');
$forms = Form::whereIn('user_id',$users);
return $forms;
}
我想获取不属于任何admin
答案 0 :(得分:0)
您可能正在寻找doesntHave。
{{1}}
答案 1 :(得分:0)
为什么不简单地反过来呢?
$forms = Form::whereNotIn('user_id', $users);