Laravel 8如何使用Hasmany在枢轴表上选择NOT NULL
我会简单地我想选择所有具有 data 不是null
的的所有用户
> 具有用户数据
,但其他 ID 喜欢 ID 2、3、4 没有用户数据
是null
或[]或空数组
但我不知道要实现该目标的查询而且我不知道该代码控制器或模型?
,这是我的控制器
public function index()
{
return Project::with('users')->get();
}
这是我的模型项目
public function users(){
return $this->belongsToMany(User::class)
->withPivot('salary')->
->using(project_user::class);
}
希望您能可以帮助我
i will make it simple i want to select all the users
where that have a data not null
like this in photo the ID 1 has a users data
but the others ID like ID 2, 3 ,4 don't have a users data
it's NULL
or [] or empty Array
but i don't have a idea what kind of query to achieve that goal and i don't have a idea where to put that code CONTROLLER or MODEL?
so here is my CONTROLLER
public function index()
{
return Project::with('users')->get();
}
here is my MODEL Project
public function users(){
return $this->belongsToMany(User::class)
->withPivot('salary')->
->using(project_user::class);
}
hopefully you can help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样?
Like this?