【发布时间】:2022-11-11 01:20:24
【问题描述】:
我的桌子
- 用户
id name Cell 1 Cell 2 Cell 3 Cell 4 - 组
id name Cell 1 Cell 2 Cell 3 Cell 4 - group_users
id user_id group_id Cell 1 Cell 2 Cell 4 Cell 3 Cell 4 Cell 6 // All users which are members of group public function users() { return $this->belongsToMany(User::class); }// All groups user belong to public function groups() { return $this->belongsToMany(Group::class); }这就是我试图做的。我认为问题在于我必须使 $users 成为一个已获取的 id 数组,而我无法做到这一点。请帮忙
public function show(Group $group) { //Fetching all members of the group $users = $group->users()->get() return Inertia::render('Clients/Show', [ 'users' => Group::whereNotIn('id', $users)->get() ]); }
【问题讨论】:
标签: php laravel eloquent-relationship