4

I was wondering if there is a way to use whereIn with an array of arrays, something like the where with array

User::where(['user_id' => $currentUser, 'group_id' => $currentGroup]);

so i'm looking for this:

User::whereIn(['group' => $availableGroups, 'session' => $currentSessions]).

which should be equivalent to using the whereIn clause twice.

I was thinking of solving this like:

foreach (query as $key => $value)
   $userQuery->whereIn($key, $value);

I was wondering if there is a better way.

NiRR
  • 4,782
  • 5
  • 32
  • 60

1 Answers1

4

No that's not possible. You have to use whereIn() multiple times (or in a loop).

There's no logic that would handle such a parameter correctly:

public function whereIn($column, $values, $boolean = 'and', $not = false)
{
    $type = $not ? 'NotIn' : 'In';

    // ... irrelevant code omitted ...

    $this->wheres[] = compact('type', 'column', 'values', 'boolean');

    $this->addBinding($values, 'where');

    return $this;
}
lukasgeiter
  • 147,337
  • 26
  • 332
  • 270
  • I don't understand what you mean by "no logic that would handle ..." – NiRR Jun 08 '15 at 12:25
  • The code I posted is from the framework core. If an array of arrays was supported, the method would contain logic to handle that. Probably call `whereIn` for every subarray... I added this code to prove my statement. – lukasgeiter Jun 08 '15 at 12:38