I am working on a Laravel dynamic where
clause eloquent model. I want to find the collection with the size of an array field having size values greater than, less than, between and not equal to.
I am using jenssegers
and in the jenssegers
documentation, the code to find documents with array size to a specific value is given, but I need to use it to find
<,>,!=
and between
.
User::where('tags', 'size', 3)->get();
I can't use aggregate and $where since I am using a dynamic where clause to find the desired result.
Finally, I fixed the issue myself. The answer is:
$query->whereRaw(['$where' => 'this.tags.length > 1'])