action button in topbar

Hi! I'm trying to put an action button on the topbar, but nothing is happening when I click on the action. My code is like this: Livewire component:
public function customAction(): Action
{
return Action::make('Buscar Pacote')
->requiresConfirmation()
->label('Custom Action')
->color('gray');
}
public function render()
{
return view('livewire.scan-action');
}
public function customAction(): Action
{
return Action::make('Buscar Pacote')
->requiresConfirmation()
->label('Custom Action')
->color('gray');
}
public function render()
{
return view('livewire.scan-action');
}
Hook on the panel provider:
return $panel
->renderHook(
PanelsRenderHook::GLOBAL_SEARCH_BEFORE,
fn (): string => Blade::render('@livewire(\'scan-action\')'),
)
return $panel
->renderHook(
PanelsRenderHook::GLOBAL_SEARCH_BEFORE,
fn (): string => Blade::render('@livewire(\'scan-action\')'),
)
Solution:
Ah, it’s because the name of the action doesn’t match the output in the blade file. Action::make(‘custom’) {{ $this->customAction }}...
Jump to solution
10 Replies
Lara Zeus
Lara Zeus2w ago
what in the view: livewire.scan-action try adding <x-filament-actions::modals />
Mateus
Mateus2w ago
it's already like this
<div>
{{ $this->customAction }}
<x-filament-actions::modals />
</div>
<div>
{{ $this->customAction }}
<x-filament-actions::modals />
</div>
awcodes
awcodes2w ago
based on the code you shared, there's no ->action() on the Action so, you're not telling it to actually do anything. 🙂
Mateus
Mateus2w ago
Really, I would like to pass an view, where I would normally use
->modalContent(fn() => view('view')),
->modalContent(fn() => view('view')),
how would I do this?
awcodes
awcodes2w ago
ModalContent should work. The confirmation doesn’t make sense to me in that use case. 😀 but you can also do ->action(fn() => null) if you need to.
Mateus
Mateus2w ago
It still doesn't work, I put
dd('test')
dd('test')
inside
->action()
->action()
and it wasn't called, code:
return Action::make('Custom Action')
->label('Custom Action')
->modalContent(fn() => view('my-view'))
->color('gray')
->action(fn() => null);
return Action::make('Custom Action')
->label('Custom Action')
->modalContent(fn() => view('my-view'))
->color('gray')
->action(fn() => null);
awcodes
awcodes2w ago
Which Action class did you import?
Mateus
Mateus2w ago
use Filament\Actions\Action;
Solution
awcodes
awcodes2w ago
Ah, it’s because the name of the action doesn’t match the output in the blade file. Action::make(‘custom’) {{ $this->customAction }}
Mateus
Mateus2w ago
EXACTLY THAT! thank you very much @awcodes 😀
Want results from more Discord servers?
Add your server