eproLARA's avatar

Custom Metrics per Resource on Laravel Nova Detail Page

Hello Laracasts Community,

I'm currently working on a project using Laravel Nova and have encountered a need for a feature that I believe could significantly enhance its functionality. The feature involves displaying custom metrics on a per-resource basis on the detail page of each resource.

For example, imagine I have a User resource and I want to display a custom metric on the detail page for User 12 (and indeed, for all other users). This custom metric would be specific to that user and would provide more granular insights into the data related to that user.

As it stands, Laravel Nova allows the creation of custom metrics that can be displayed on a resource's index page. However, I haven't found a way to display these metrics on a per-resource basis on the detail page of the resource.

I have already posted this question on the Laravel Nova Discord server, but I wanted to bring it to the attention of the Laracasts community as well to gather more feedback, and to find out if anyone has encountered a similar need or found a workaround.

In the event that no existing solution is available, I believe this could be a valuable feature request for Laravel Nova. I'd love to hear your thoughts on this matter.

Thank you in advance for your time and insights.

Remember to check the community guidelines for Laracasts before posting your request. I hope this helps, and please let me know if you need any further assistance!

0 likes
2 replies
hellie3's avatar

As i know Start by defining the custom metric you want to display. This could be a value derived from the resource's data or any other relevant information. Register the Custom Metric: In your Nova resource class use the withMeta method to register the custom metric. This method allows you to pass additional data to the resource's Vue component. For example, you can define a method called customMetrics that returns an array of metric data.

Shaden's avatar

I just came across this post. and I had the same requirement. you can access the resource from the request

$ResourceId = $request->resourceId

But make sure only on detail page, as the index I guess will not have the resource Id. To avoid any errors I use

 if(isset($request->resourceId) && $request->resourceId != null) {
   $Model = Model:: find($request->resourceId);
}

Please or to participate in this conversation.