Redirect with ->url() with bulk action?

I have a table and I would like to redirect to a route after selecting some records from the table. I tried using ->url(), but it doesn't work, is it possible? My code is this:
BulkAction::make('pdf')->label('Generate PDF')->icon('heroicon-o-document')
->color('info')
->url(fn ($records): string => route('step.pdf', ['steps' => $records]))
->openUrlInNewTab()
BulkAction::make('pdf')->label('Generate PDF')->icon('heroicon-o-document')
->color('info')
->url(fn ($records): string => route('step.pdf', ['steps' => $records]))
->openUrlInNewTab()
Any ideas on how to resolve it? I tried with Action also returning route, but it was not possible. Thanks.
1 Reply
marcosmarcolin
marcosmarcolin4mo ago
I did something like this to surprise, but I don't think it's ideal.
->bulkActions([
BulkAction::make('pdf')->label('Generate PDF')->icon('heroicon-o-document')
->color('info')
->action(function ($records, $livewire) {
$ids = [];
foreach ($records as $record) {
$ids[] = $record->id;
}

$ids = implode(',', $ids);

$livewire->redirectRoute(
'step',
['step' => $ids]
);
})
]);
->bulkActions([
BulkAction::make('pdf')->label('Generate PDF')->icon('heroicon-o-document')
->color('info')
->action(function ($records, $livewire) {
$ids = [];
foreach ($records as $record) {
$ids[] = $record->id;
}

$ids = implode(',', $ids);

$livewire->redirectRoute(
'step',
['step' => $ids]
);
})
]);