Chart with a param or Chart for a specific model #532
-
Hi, I want to create a widget chart for a specific model in the show operation route. But I can't find a way to send custom data to the chart. Is that possible? Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Hello Diogo, Thanks for posting the question. The standard chart widget does not pass any data to the chart controller. However, you can create a custom chart widget by copying the one shipped with our PRO package and modifying the code at the top: @php
$controller = new $widget['controller'];
$controller->model_id = $widget['model_id'];
@endphp The extra parameter can be passed when defining the widget: Widget::add([
'type' => 'chart',
'controller' => \App\Http\Controllers\Admin\Charts\WeeklyUsersChartController::class,
'model_id' => 10, // <-- can by anything
]); Hope this helps. Feel free to post follow-up questions if you have any. Thanks! |
Beta Was this translation helpful? Give feedback.
-
@phpfour Thank you very much for your help. However I'm not able to get the model_id on the chart controller. But I'm not able to get that custom param on either controller methods: Can you please help me? |
Beta Was this translation helpful? Give feedback.
-
@phpfour I've managed to do it in the controller, but grabbing the param from the url. Please share if you know a better way of getting the param that I'm sending to the widget. |
Beta Was this translation helpful? Give feedback.
-
Due to no activity, I will close this issue, but please feel free to reopen or create a new one if needed. Cheers. |
Beta Was this translation helpful? Give feedback.
Hello Diogo,
Thanks for posting the question. The standard chart widget does not pass any data to the chart controller. However, you can create a custom chart widget by copying the one shipped with our PRO package and modifying the code at the top:
The extra parameter can be passed when defining the widget:
Hope this helps. Feel free to post follow-up questions if you have any.
Thanks!