I have a repository function that gets data by using:
public function get($request){
return User::where($request)->get();
}
where the $request array is dynamic. The above works well as long as I pass in regular key value pairs:
$request = array(
'name' => 'mike',
'age' => 45
);
The above translates to this SQL:
SELECT *
FROM users
WHERE name = 'mike' AND age = 45;
Every once in a while, I would like to pass in an array as one of the properties for $request:
$request = array(
'name' => 'mike',
'age' => array(45, 46)
)
and have it translate into the following SQL:
SELECT *
FROM users
WHERE name = 'mike' AND age IN(45, 46);
Any properties set as an array in $request should be treated as a where in statement as opposed to a vanilla where statement.
How would I do this?