F
Filament16mo ago
lukevi

renderHook scopes don't work

Hi- I'm new to this so probably doing it wrong: in panel():
->renderHook(
'panels::content.end',
fn (array $scopes): View => view('extra-stuff', ['scopes' => $scopes]),
// scopes: [
// \App\Filament\Resources\ClientResource::class,
// \App\Filament\Resources\ClientResource\Pages\ListClients::class
// ]
);
->renderHook(
'panels::content.end',
fn (array $scopes): View => view('extra-stuff', ['scopes' => $scopes]),
// scopes: [
// \App\Filament\Resources\ClientResource::class,
// \App\Filament\Resources\ClientResource\Pages\ListClients::class
// ]
);
with the scopes uncommented, I would expect to see my extra stuff under client list/view/edit etc, right? if I comment out the scopes, my content appears, but otherwise it does not. I'm freshly updated on v3.0.30 after trying this for a while on .27. TIA for any advice! update to add: when I @dump($scopes) in my view, it's an empty array every time.
7 Replies
lukevi
lukeviOP16mo ago
In case anyone else has a similar issue - I was able to get around this. Instead of using scopes, I registered the renderHook down in the specific page where I need it. So, in ListClients, I extend the parent mount() method:
public function mount(int | string $record): void
{
parent::mount($record);

FilamentView::registerRenderHook(
'panels::content.end',
fn (): View => view('extra-stuff', ['record' => $this->record])
);
}
public function mount(int | string $record): void
{
parent::mount($record);

FilamentView::registerRenderHook(
'panels::content.end',
fn (): View => view('extra-stuff', ['record' => $this->record])
);
}
I'm still very open to knowing what's wrong with how I was trying to use scopes before. Edit: as a bonus, by doing this here and calling parent::mount first, I can pass the instantiated model into my view..
LeandroFerreira
LeandroFerreira16mo ago
panels::page.end ?
lukevi
lukeviOP16mo ago
Thank you Leandro - that does work! And when I dump the $scopes param now, it does contain what we'd expect-
array:2 [// resources/views/extra-stuff.blade.php
0 => "App\Filament\Resources\ClientResource\Pages\ListClients"
1 => "App\Filament\Resources\ClientResource"
]
array:2 [// resources/views/extra-stuff.blade.php
0 => "App\Filament\Resources\ClientResource\Pages\ListClients"
1 => "App\Filament\Resources\ClientResource"
]
LeandroFerreira
LeandroFerreira16mo ago
{{ $this->record }} in the blade file?
lukevi
lukeviOP16mo ago
And yes, that works too (in the specific edit/view pages that is, and we wouldnt expect it in the list view). Thanks for your help!
LeandroFerreira
LeandroFerreira16mo ago
worked?
lukevi
lukeviOP16mo ago
100% works - I can set the render hooks up at the provider level, and only show them for specific scopes as I was hoping to do. Plus the bonus of having the record available to my custom view works too.
Want results from more Discord servers?
Add your server