ricardom_vieira's avatar

Nova Value Metrics - Format not working

Hello, I can't seem to get Nova's formatting for the Value Metrics to work. Simply nothing happens when I add the property to my return.

Any hints on what might be wrong?

$total = DB::table(hello')
        ->sum(DB::raw('bye'));

      return $this
        ->result($total)
        ->format("0,0");
0 likes
7 replies
ejdelmonico's avatar

You should show the entire metric for context. Try using count instead of result.

ricardom_vieira's avatar

Thanks for reply!

What do you mean by showing the whole metric? This pretty much all there is to it.

public function calculate(Request $request)
    {

     $total = DB::table('hello')
        ->sum(DB::raw('bye'));

      return $this
        ->result($total)
        ->format("0,0");
    }

In this metrics, I need to show a sum and not a count. Using count would work, but that doesn't serve what I'm looking for.

devfrey's avatar

Why not use sum()?

public function calculate($request)
{
    return $this->sum($request, YourModel::class, 'column_name')
        ->format('0,0');
}
ricardom_vieira's avatar
<?php

namespace App\Nova\Metrics;

use App\Models\Hello;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Laravel\Nova\Metrics\Value;

class HelloMetrics extends Value
{
    /**
     * Calculate the value of the metric.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return mixed
     */
    public function calculate(Request $request)
    {

      return $this->sum($request, Hello::class, 'bye')
        ->format('0,0');
    }

Still doesn't work.

The total of sum = 12143, but the metrics show 12.14k.

Please or to participate in this conversation.