Current Record in Render Hook

Hey! I want to use the Render Hook PanelsRenderHook::BODY_START and render custom view depending on the current record. I specified the scope, so that it is only displayed on a specific resource page but struggle to get the current resource record in my new view in order to display the necessary information. Does anyone know how the get or inject the current record in a render hook?
2 Replies
PunchRockgroin
PunchRockgroin8mo ago
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.
Lara Zeus
Lara Zeus8mo ago
FilamentPHP Glow
when you don't have access to the current resource or page, current for the help!
Want results from more Discord servers?
Add your server