Value

You're browsing the documentation for an old version of MoonShine. Consider upgrading your project to MoonShine 2.x.

Displays a simple value, such as how many specific records a table contains

namespace MoonShine\Resources;
 
use MoonShine\Metrics\ValueMetric;
 
class PostResource extends Resource
{
//...
 
public function metrics(): array
{
return [
ValueMetric::make('Completed orders')
->value(Orders::completed()->count())
];
}
 
//...
}

You can also display a value as a goal progress indicator

namespace MoonShine\Resources;
 
use MoonShine\Metrics\ValueMetric;
 
class PostResource extends Resource
{
//...
 
public function metrics(): array
{
return [
ValueMetric::make('Open orders left')
->value(Orders::completed()->count())
->progress(200) // Ultimate goal
];
}
 
//...
}

You can add formatting, prefix, and suffix to the output value

namespace MoonShine\Resources;
 
use MoonShine\Metrics\ValueMetric;
 
class PostResource extends Resource
{
//...
 
public function metrics(): array
{
return [
ValueMetric::make('Revenue')
->value(Orders::completed()->sum('price'))
->valueFormat('for today {value} rub.')
];
}
 
//...
}