lundi 27 août 2018

Laravel Nova metrics filtering

I have a model called Property which has an 'active' flag. I want a metric at the top of my resource which shows a count of active Properties.

My calculate method is exactly as in the doc but this shows all Properties rather than active ones:

public function calculate(Request $request)
{
    return $this->count($request, Property::class);
}

How can I add a filter?

I've tried a where clause:

public function calculate(Request $request)
{
    return $this->count($request, Property::class)->where('active','=',1);
}

And a query scope:

public function calculate(Request $request)
{
    return $this->count($request, Property::class)->active();
}

I thought I might be able to use the Nova filter I set up on the resource list page but that didn't seem to work either. I'm sure it's really easy but I haven't worked it out. Thanks for your help!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2BSdtpS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire