Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kris01's avatar

Laravel Nova Metrics

Hi,

I have created a Nova metric for the total users. But it doesn't return the true result. I tried with other models and works, but the user one is returning wrong count of users

0 likes
1 reply
ramonrietdijk's avatar

Sharing some of your code like your metric would be very helpful in order to see why this happens. Since your metric is called Total Users I assume that it is a Value metric and you have removed the ranges() method?

By default Laravel Nova uses ranges so it could be possible that the users are not included in the result.

You can overcome this by returning your own result.

use Laravel\Nova\Metrics\ValueResult;

public function calculate(NovaRequest $request)
{
    return new ValueResult(User::query()->count());
}

Alternatively if you are using ranges, you could add the key ALL to your ranges array.

public function ranges()
{
    return [
        'ALL' => __('All'),
    ];
}

Please or to participate in this conversation.