Partition Metrics - Access nested JSON Field
- Laravel Version: ^10.0
- Nova Version: 4.26.5
- PHP Version: 8.2.4
- Database Driver & Version: pdo_mysql, mysqlnd 8.2.4
Description:
In my partition metric I want to access a nested JSON field.
public function calculate(NovaRequest $request) {
return $this->count($request, User::class, 'meta->notifications->newsletters');
}
However, I don't get any correct data back.
If I make a query directly to the database:
SELECT JSON_UNQUOTE(JSON_EXTRACT(meta, '$.notifications.newsletters')) AS opt, COUNT(*) as aggregate FROM users GROUP BY opt;
Do I get the following data:
| opt | aggregate |
|---|---|
| true | 58 |
| false | 13 |
| NULL | 1 |
It seems that in the file /vendor/laravel/nova/src/Metrics/Partition.php, when calling the function formatAggregateResult, an empty string is passed for $key.
Released with Laravel Nova 5.0.0
Feel free to open up a new issue if you're still experiencing this problem on the latest version.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.