You can assign custom data to a widget as follows.
Also, remember that the $record is already exposed to livewire.
<?phpnamespace App\Filament\Widgets; use Filament\Widgets\Widget; class NewWidget extends Widget{ public $widgetData; protected static string $view = 'widgets.new-widget'; protected int | string | array $columnSpan = 12; public function mount(): void { $this->widgetData = [ 'custom_title' => "Your Title Here", 'custom_content' => "Your content here" ]; }}
Then for the view:
<x-filament::widget> <x-filament::card> <x-slot name="heading"> {{ $widgetData["custom_title"] }} </x-slot> {{ $widgetData["custom_content"] }} </x-filament::card></x-filament::widget>
Filament already have a method pass data to the view, no need to create a custom method for this. Simply add this to your widget:
then in the view, just:
but how to pass data from an edit page or view page to the widget other than the record?
Had the same question. Looking at the view-record page source code, $record is being exposed to the widget via this line
Your can probably copy the the blade file into your own directory, add any data to the prop and overwrite the
in either your Edit or View page.
This is an incredibly useful tips for many reasons:
So I have this:
class NasWidget extends DiskIoChart { public ?Model $record = null; protected static ?string $heading = 'Chart';
Thanks for the tips! Ps I really tried getting the code formatting right but I don't know how.