F
Filament12mo ago
ericmp

Redirect after bulk action

is this how u would redirect after a bulk action is completed?
Tables\Actions\BulkAction::make('create_playlist')
->action(function (Collection $records) {
$playlist = Playlist::create([
'name' => null,
]);

$playlist->songs()->attach($records);

return to_route('filament.admin.resources.playlists.edit', $playlist);
})
->icon('heroicon-o-plus')
->color(Color::Indigo)
,
Tables\Actions\BulkAction::make('create_playlist')
->action(function (Collection $records) {
$playlist = Playlist::create([
'name' => null,
]);

$playlist->songs()->attach($records);

return to_route('filament.admin.resources.playlists.edit', $playlist);
})
->icon('heroicon-o-plus')
->color(Color::Indigo)
,
i tried to use $this->to_route() but im not in an object context i prefer $this->to_route() since is the livewire one. the return to_route() is the laravel one. and the diference is that the filament notifications/livewire stuff glitches a little bit, just a little, before redirecting. instead, the livewire one doesnt do it ^^
15 Replies
ericmp
ericmpOP12mo ago
anyone?
awcodes
awcodes12mo ago
Inject $livewire into the ->action() callback then you can call it.
$livewire->to_route()
$livewire->to_route()
ericmp
ericmpOP12mo ago
how can inject it? i get this:
No description
ericmp
ericmpOP12mo ago
im also unable to get the name, which i have filled in the form :/ i cant inject $get
ericmp
ericmpOP12mo ago
but isnt that what i have done? i missed the type Component? still get same error though maybe for bulk actions is different?
awcodes
awcodes12mo ago
In livewire v3 it’s ->redirectRoute('profile')
ericmp
ericmpOP12mo ago
oh u r right omg thanks
awcodes
awcodes12mo ago
There is no to_route() method as the error is telling you.
ericmp
ericmpOP12mo ago
yeah 🥲
marcosmarcolin
marcosmarcolin10mo ago
@ericmp Hi, did you manage to solve it? I am in the same.
ericmp
ericmpOP10mo ago
hi, i did it this way:
Tables\Actions\BulkAction::make('create_playlist')
->form([
Forms\Components\TextInput::make('name')
->autofocus()
->required()
->unique(Playlist::class)
,
])
->action(function (Collection $records, Component $livewire, array $data) {
$playlist = Playlist::create([
'name' => $data['name'],
]);

$playlist->songs()->attach($records);

$livewire->redirectRoute('filament.admin.resources.playlists.edit', $playlist);
})
->icon('heroicon-o-plus')
->color(Color::Indigo)
,
Tables\Actions\BulkAction::make('create_playlist')
->form([
Forms\Components\TextInput::make('name')
->autofocus()
->required()
->unique(Playlist::class)
,
])
->action(function (Collection $records, Component $livewire, array $data) {
$playlist = Playlist::create([
'name' => $data['name'],
]);

$playlist->songs()->attach($records);

$livewire->redirectRoute('filament.admin.resources.playlists.edit', $playlist);
})
->icon('heroicon-o-plus')
->color(Color::Indigo)
,
marcosmarcolin
marcosmarcolin10mo ago
Hi @ericmp, It was the solution I found too, thanks for your time. https://discord.com/channels/883083792112300104/1209647616023863308
ericmp
ericmpOP10mo ago
nicee. but what is the link u share below? is another problem u have or is related?
marcosmarcolin
marcosmarcolin10mo ago
It's a similar problem to what you were experiencing, I ended up opening the topic before finding this one.
Want results from more Discord servers?
Add your server