Metrics on Lenses do not receive applied filters #5133
-
Description:Metrics on Lenses do not receive applied filters. Metrics property Detailed steps to reproduce the issue on a fresh Nova installation:Let's have a metric: class PostsPerStatus extends Partition
{
public function calculate(NovaRequest $request)
{
$statuses = Post::availableStatuses(true);
logger(print_r([get_class($request), $this->filters], true));
return $this
->count($request, Post::class, 'status')
->label(function ($v) use ($statuses) {
return $statuses[$v] ?? 'UNKNOWN';
});
}
}And add it to // ...Nova\Resources\Post.php
public function cards(NovaRequest $request)
{
return [
PostsPerStatus::make()->refreshWhenFiltersChange(),
];
} // ...Nova\Lenses\PostsViaLens.php
public function cards(NovaRequest $request)
{
return [
PostsPerStatus::make()->refreshWhenFiltersChange(),
];
}On Resource Index page metric DO receive filters. But on Resource Lens page metric DO NOT receive filters. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
It is much easier to match Eloquent query for Metric with Resource and automatically applying Filters tends to work out of the box. Lens, however, offers full customization to build the query using |
Beta Was this translation helpful? Give feedback.


It is much easier to match Eloquent query for Metric with Resource and automatically applying Filters tends to work out of the box.
Lens, however, offers full customization to build the query using
Eloquentor Fluent Query Builder and the filters query may not match the Metric query.