Get stream entries if checkbox is checked
Created 4 years ago by finnito

I have a stream where one of the fields is a set of checkboxes that are used to assign and document to one or more categories. How can I make an entries() query to extract documents which have a particular checkbox? This is what I've tried:

{% set files = entries("ucandance", "documents") .where(request_segment(2), "in", "tags") .get() %}

But .where() takes the arguments in the opposite order.

ryanthompson  —  4 years ago Best Answer

where should be what you use but you want to use LIKE since checkboxes store a serialized value array:

where('tags', 'LIKE', '"%' ~ request_segment(2) ~'%"')

Keep in mind where works exactly like the query builder in Laravel. You're basically using the query builder at this point. The segment part is basically just a wildcard to match the string in the column which again is serialized.

Hope this helps!

finnito  —  4 years ago

Got it! Thanks :D

vedatakd  —  2 years ago

for php;

->whereRaw('column_name REGEXP \'.;s:[0-9]+:"'.$searchVal.'".\'')->get();