Use Laravel Nova Filter for Metric?

753 Views Asked by At

I have a Filter configured for my Nova Resource. It applies the status:

public function apply(Request $request, $query, $value)
{
    return $query->where('status', $value);
}

This works fine for the Table, but I have some Metrics configured on the Index as well. Is there a way for me the apply the active filter also on the Metric itself?

The is the Calculate method:

public function calculate(NovaRequest $request)
{
    // apply the active Filter on this
    return $this->count($request, Intake::class, 'type');
}
1

There are 1 best solutions below

1
On

You can replace Intake::class with a Builder object.

return $this->count($request, Intake::where('active', 1), 'type');