Reputation: 1306
I'm trying to implement a basic filter using Laravel Nova. The filter looks at the field "onboarded_at," which is a datetime field. If the attribute has a timestamp, they're onboarded, and if not, they aren't.
Here's my filter:
public function apply(Request $request, $query, $value)
{
return $query->where('onboarded_at', $value);
}
public function options(Request $request)
{
return [
'Onboarded' => !NULL, // How would I indicate a non-null value here?
'Not Onboarded' => NULL,
];
}
How would I indicate a non-null value in the options function?
Upvotes: 2
Views: 1446
Reputation: 25161
Use the $value
param to modify the query as desired:
public function apply(Request $request, $query, $value)
{
if($value) {
return $query->whewhereNotNull('onboarded_at');
}
return $query->whereNull('onboarded_at');
}
public function options(Request $request)
{
return [
'Onboarded' => 1,
'Not Onboarded' => 0,
];
}
Upvotes: 2