I'm building a query for Laravel Scout.
$subchanResults = Subchan::search($query)
->when($request->input('incl_nsfw'), function ($query, $incl_nsfw) {
if ($incl_nsfw == 0) {
return $query->where('nsfw','!=', 'always');
}
}, function ($query) {
return $query->where('nsfw','!=', 'always');
})
->paginate(3);
Laravel Scout only allows basic where clauses, no advanced conditional clauses of any kind, so it's been kind of tricky so far. (Documentation: https://laravel.com/docs/8.x/scout#where-clauses)
My problem is with this line: return $query->where('nsfw','!=', 'always');
It seems that Scout will allow a simple where('column','value')
, but if I try to add the 3rd parameter to the where clauses (not equal), it doesn't work.
How can I make this query work? Or do I have to manually trim the results myself after the query?