How to add a view and pass a data? #1357
-
This is how to add html before a content in setupShowOperation. How to add a view and pass a data? ` $userCount = \App\Models\User::count();
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
To add a custom view and pass data to it as a widget in Backpack, you should use the widget type view and provide the path to your Blade file along with the data you want to pass. Here’s how you can do it: Widget::add([
'type' => 'view',
'view' => 'your.custom.view', // path to your Blade file
'data' => [
'userCount' => $userCount, // pass your data here
// add more variables as needed
],
])->to('before_content'); In your Blade file (e.g., <div>
There are {{ $userCount }} users.
</div> This approach allows you to render any custom Blade view and pass any data you need to it. The documentation for widgets confirms you can use the view type and pass data using the data attribute, though the specific example is not shown in the docs, this is the standard way Backpack handles view widgets and data passing in Laravel Blade views. If you need to include multiple widgets in a row, you can use the div widget as shown in your example, and include your view widget inside its content array as well. For more details, see the Backpack widgets documentation and the show operation widgets example. ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️ Relevant sources: Widgets|Livewire |
Beta Was this translation helpful? Give feedback.
-
from the code here, $userCount returns undefined in blade. Widget::add([ |
Beta Was this translation helpful? Give feedback.
-
Hello @smzapp Try with this As our docs says, any attribute will be available inside $widget var, so look for data there. Cheers. |
Beta Was this translation helpful? Give feedback.
-
Here is an example. The docs are not very helpful.
and I have this the blade file -
You don't have to use data you could name it the actual variable name and reference it like $widget['variable_name'] |
Beta Was this translation helpful? Give feedback.
Here is an example. The docs are not very helpful.
In my show I have -
and I have this the blade file -