2

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.

Ravi Shankar Bharti
  • 8,922
  • 5
  • 28
  • 52
Abhi Das
  • 500
  • 8
  • 11

1 Answers1

2

Finally, I fixed the issue myself. The answer is:

$query->whereRaw(['$where' => 'this.tags.length > 1'])

Dexter Bengil
  • 5,995
  • 6
  • 35
  • 54
Abhi Das
  • 500
  • 8
  • 11