Help with action modal

Hi everyone, I'm trying to have a action modal rendered via a panel render hook, but I can't seem to get the action to do anything. Trying multiple YouTube videos/tutorials, it's not even giving me an error, just not doing anything. Livewire component:
class SwitchHotels extends Component implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;

public function renderHotelSwitch()
{
return Action::make('switchHotel')
->label('Switch Hotel')
->icon('heroicon-m-building-office-2')
->form([
Select::make('hotel_id')
->label('Switch Hotel')
->options(function () {
return Hotel::pluck('name', 'id')->toArray();
})
->required()
])
->action(function (array $data): void {
$hotel = Hotel::findOrFail($data['hotel_id']);

auth()->user()->update([
'current_hotel_id' => $hotel->id
]);

$this->redirect(request()->header('Referer'));
});
}

public function render()
{
return view('livewire.switch-hotels');
}
}
class SwitchHotels extends Component implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;

public function renderHotelSwitch()
{
return Action::make('switchHotel')
->label('Switch Hotel')
->icon('heroicon-m-building-office-2')
->form([
Select::make('hotel_id')
->label('Switch Hotel')
->options(function () {
return Hotel::pluck('name', 'id')->toArray();
})
->required()
])
->action(function (array $data): void {
$hotel = Hotel::findOrFail($data['hotel_id']);

auth()->user()->update([
'current_hotel_id' => $hotel->id
]);

$this->redirect(request()->header('Referer'));
});
}

public function render()
{
return view('livewire.switch-hotels');
}
}
And How I render it:
FilamentView::registerRenderHook(PanelsRenderHook::GLOBAL_SEARCH_AFTER, function() {
return Blade::render("<livewire:switch-hotels />");
});
FilamentView::registerRenderHook(PanelsRenderHook::GLOBAL_SEARCH_AFTER, function() {
return Blade::render("<livewire:switch-hotels />");
});
Any help appreciated.
Solution:
rename renderHotelSwitch function to switchHotelAction Then, use {{ $this->switchHotelAction }}...
Jump to solution
5 Replies
Никола Стојков
Also the view:
<div>
{{ $this->renderHotelSwitch() }}

<x-filament-actions::modals />
</div>
<div>
{{ $this->renderHotelSwitch() }}

<x-filament-actions::modals />
</div>
Solution
LeandroFerreira
rename renderHotelSwitch function to switchHotelAction Then, use {{ $this->switchHotelAction }}
Никола Стојков
Ayyy lmao that worked Probably missed that magic in the documentation? I'll double check, if not I'll send PR to update docs
Никола Стојков
I guess I'm just bad at reading documentation. Thanks a lot friend!

Did you find this page helpful?