Reputation: 545
I am creating a query in laravel via models to filter out what is/isnt already in a group.
Models:
Filters in place:
function members()
Groups->hasMany(GroupMembers)
Trying to achieve this:
Users->whereNotIn(Groups->members())
This is the lines of code in question, how the rest of it is all built I believe to be irrelevant:
$groups = Groups::find($request['id']);
// die($groups->members);
return view('admin.groups.add_member',
['group' => $groups,
'users' => User::whereNotIn('id', $groups->members->user)]);
the die() command returns the lines of the members successfully. The return statement groups->members returns an array of [1,1,1] (this is the group id where there are 3 members of the group)
I am sure its something simple but some help would be appreciated!
Upvotes: 0
Views: 122
Reputation: 25926
Try something like this (assuming the column is called user_id
):
User::whereNotIn('id', $groups->members->pluck('user_id'))->get()
Upvotes: 2