Answer the question
In order to leave comments, you need to log in
Laravel Eloquent JSON Contains, how to pass an array to a function and check for the presence of one of the elements in the database?
Hi here is my function code
protected function room_count($room_count)
{
$query = $this->builder
->whereJsonContains('rent_requests.rooms_count', $room_count);
return $query;
}
Answer the question
In order to leave comments, you need to log in
Got it, here is the final solution
// Room Count Filter
protected function room_count($room_count)
{
return $this->builder
->where(function($query) use($room_count){
$query->whereJsonContains('rent_requests.rooms_count', $room_count[0]);
for($i = 1; $i < count($room_count); $i++) {
$query->orWhereJsonContains('rent_requests.rooms_count', $room_count[$i]);
}
return $query;
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question