PunchRockgroin
PunchRockgroin
FFilament
Created by therouv on 3/22/2024 in #❓┊help
Current Record in Render Hook
So I came across your question as I had the same issue (getting the current record into a render hook). I had seen elsewhere where Filament::registerRenderHook was being used in the getHeaderActions() function call in individual Resource Pages, and I figured you could just pass the record along using $this->record(). It works! I've also used the booted() lifecycle hook which does the same. You then just get the record into the view, or pass it to a livewire component.
public function booted()
{
Filament::registerRenderHook(
PanelsRenderHook::PAGE_START,
fn(): View => view('components.test-view')->with([
'record' => $this->record
])
// fn(): string => \Illuminate\Support\Facades\Blade::render('@livewire(\'some-livewire-component\', [\'record\' => $record])', ['record' => $this->record]),
);
}
public function booted()
{
Filament::registerRenderHook(
PanelsRenderHook::PAGE_START,
fn(): View => view('components.test-view')->with([
'record' => $this->record
])
// fn(): string => \Illuminate\Support\Facades\Blade::render('@livewire(\'some-livewire-component\', [\'record\' => $record])', ['record' => $this->record]),
);
}
I would also bet you could just use Livewire events to pass whatever data you need to along to other Livewire components. Is it the best way? Probably not, but it works for my needs until something "official" is known.
3 replies