Reputation: 621
I have an array with values 1,2. for example.
$arr = []
foreach($permission as $perm)
{
$arr[] = $perm->permission
}
dd(implode(',',$arr));
result shows 1,2
but when i use the $arr in query its not working proper. I am using this in following query
$response = implode(',',$arr);
$role = Role::whereNotIn('id',[$response])->get();
//means select * from role where id not in (1,2);
but it works like below
select * from role where id not in (1);
can you guys please help me to resolve this
Upvotes: 4
Views: 4703
Reputation: 163978
You're passing a string which is "1,2". You must pass an array not a string to the whereNotIn()
method:
$role = Role::whereNotIn('id', $arr)->get();
Upvotes: 5