Learn how to define metrics in Nova.
nova:value
Artisan command. By default, all new metrics will be placed in the app/Nova/Metrics
directory:
calculate
method. This method should return a Laravel\Nova\Metrics\ValueResult
instance. Don’t worry, Nova ships with a variety of helpers for quickly generating metric results.
In this example, we are using the count
helper, which will automatically perform a count
query against the specified Eloquent model for the selected range, as well as automatically retrieve the count for the “previous” range:
count
helper. You may also use a variety of other aggregate functions when building your metric. Let’s explore each of them now.
average
method may be used to calculate the average of a given column compared to the previous time interval / range:
sum
method may be used to calculate the sum of a given column compared to the previous time interval / range:
max
method may be used to calculate the maximum value of a given column compared to the previous time interval / range:
min
method may be used to calculate the minimum value of a given column compared to the previous time interval / range:
ranges
method. This method determines the ranges that will be available in the value metric’s range selection menu. The array’s keys determine the number of days that should be included in the query, while the values determine the “human readable” text that will be placed in the range selection menu. Of course, you are not required to define any ranges at all:
0
as a result containing no data. This may not always be correct, which is why you can use the allowZeroResult
method to indicate that 0
is a valid value result:
prefix
and suffix
methods when returning the ValueResult
instance:
currency
method to specify that a given value result represents a currency value. By default, the currency symbol will be $
, but you may also specify your own currency symbol by passing the symbol as an argument to the currency
method:
format
method. The format must be one of the formats supported by Numbro:
transform
helper:
result
and previous
methods, giving you full control over the calculation of these values:
nova:trend
Artisan command. By default, all new metrics will be placed in the app/Nova/Metrics
directory:
calculate
method. This method should return a Laravel\Nova\Metrics\TrendResult
object. Don’t worry, Nova ships with a variety of helpers for quickly generating results.
In this example, we are using the countByDays
helper, which will automatically perform a count
query against the specified Eloquent model for the selected range and for the selected interval unit (in this case, days):
countByDays
helper. You may also use a variety of other aggregate functions and time intervals when building your metric.
count
methods may be used to calculate the count of a given column over time:
average
methods may be used to calculate the average of a given column over time:
sum
methods may be used to calculate the sum of a given column over time:
max
methods may be used to calculate the maximum value of a given column over time:
min
methods may be used to calculate the minimum value of a given column over time:
ranges
method. This method determines the ranges that will be available in the trend metric’s range selection menu. The array’s keys determine the number of time interval units (months, weeks, days, etc.) that should be included in the query, while the values determine the “human readable” text that will be placed in the range selection menu. Of course, you are not required to define any ranges at all:
showLatestValue
method:
format
method. The format must be one of the formats supported by Numbro:
showSumValue
method when returning your values from a trend metric:
prefix
and suffix
methods:
dollars
and euros
convenience methods for quickly prefixing a Dollar or Euro sign to the trend values:
Laravel\Nova\Metrics\TrendResult
object and return it from your metric’s calculate
method. This approach to calculating trend data gives you total flexibility when building the data that should be graphed:
nova:partition
Artisan command. By default, all new metrics will be placed in the app/Nova/Metrics
directory:
calculate
method. This method should return a Laravel\Nova\Metrics\PartitionResult
object. Don’t worry, Nova ships with a variety of helpers for quickly generating results.
In this example, we are using the count
helper, which will automatically perform a count
query against the specified Eloquent model and retrieve the number of models belonging to each distinct value of your specified “group by” column:
count
helper. You may also use a variety of other aggregate functions when building your metric.
average
method may be used to calculate the average of a given column within distinct groups. For example, the following call to the average
method will display a pie chart with the average order price for each department of the company:
sum
method may be used to calculate the sum of a given column within distinct groups. For example, the following call to the sum
method will display a pie chart with the sum of all order prices for each department of the company:
max
method may be used to calculate the max of a given column within distinct groups. For example, the following call to the max
method will display a pie chart with the maximum order price for each department of the company:
min
method may be used to calculate the min of a given column within distinct groups. For example, the following call to the min
method will display a pie chart with the minimum order price for each department of the company:
colors
method when returning your partition result from the metric:
result
method, providing maximum flexibility:
nova:progress
Artisan command. By default, all new metrics will be placed in the app/Nova/Metrics
directory:
calculate
method. This method should return a Laravel\Nova\Metrics\ProgressResult
object. Don’t worry, Nova ships with a variety of helpers for quickly generating results.
In this example, we are using the count
helper to determine if we have reached our new user registration goal for the month. The count
helper will automatically perform a count
query against the specified Eloquent model:
count
helper. You may also use the sum
aggregate method when building your metric. For example, the following call to the sum
method will display a progress metric with the sum of the completed transaction amounts against a target sales goal:
avoid
method to specify that the metric is something you wish to avoid, Nova will use green to indicate lack of progress towards the “goal”, while using yellow to indicate the approaching completion of the “goal”:
prefix
and suffix
methods:
dollars
and euros
convenience methods for quickly prefixing a Dollar or Euro sign to the progress values:
result
method:
nova:table
Artisan command. By default, all new metrics will be placed in the app/Nova/Metrics
directory:
calculate
method. This method should return an array of Laravel\Nova\Metrics\MetricTableRow
objects. Each metric row allows you to specify a title and subtitle, which will be displayed stacked on the row:
actions
method to return an array of Laravel\Nova\Menu\MenuItem
instances, which will be displayed in a dropdown menu:
icon
method and pass in the key for the icon you wish to use:
iconClass
method to add the needed classes to the icon:
emptyText
method:
cacheFor
method which allows you to specify the duration the metric result should be cached:
name
method within your metric class: