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

noahainsworth's avatar

Laravel Nova partition metrics count query

Hi everyone! I'm fairly new on Laravel and currently working on a project using Laravel Nova. I want to use the partition metrics to display the percentage of "Loan Applications Per Company". Basically my table structures are like this:

loan_application: (id, user_id)

user: (id, user_name, company_id)

company: (id, company_name)

I'm a little lost on how I will query that from this partition-metrics function:

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

Nova docs: https://nova.laravel.com/docs/1.0/metrics/defining-metrics.html#partition-metrics

0 likes
3 replies
bryanmonzon's avatar

Since you're likely counting the relationship and not a column on the table, you'll need to use the result() method. You can query and then map over the result to get the required array. Something like this might work.

public function calculate(Request $request)
{
    $companies = Company::with('loan_application')->map(function($company) {
        return [
            $company->name => $company->loan_application->count()
        ];
        });

    return $this->result($companies->all());
}

freshyseth's avatar

This is what I'm doing, however, by default Laravel Spark limits the partitions to a total of 5. How can I get the card to show the full list of partitions?

Please or to participate in this conversation.