Here my code :
$search = request()->get('search');
$conciergerieSelect = request()->get('conciergerie');
$services = Service::get();
$prestations = Prestation::with([
'service:name'
])
->whereIn('conciergerie_ids', $conciergerieSelect)
->where('name', 'regexp', "/$search/i")
->paginate(100);
return $res = [
'prestations' => $prestations,
'services' => $services
];
I need to get all prestations where there is an conciergerie_ids
equal to $conciergerieSelect
.
conciergerie_ids
is a table of ids.
$conciergerieSelect
is an id.
I tried to use whereIn but i get an error : "Invalid supplied foreach()" Thank you.
The whereIn
method provided by Laravel accepts an array as the 2nd parameter.
Please replace the $conciergerieSelect
variable by [$conciergerieSelect]
in the whereIn
clause:
//...
->whereIn('conciergerie_ids', [$conciergerieSelect])