F
Filamentβ€’16mo ago
G3z

open new tab from Bulkaction

Is it possible to open a route in a new tab from a bulkaction ? I would like to create an action that prints warehouse labels for all the selected entities my idea is to select entities -> run the action -> open a controller in a new tab with the ids -> render a printable view Is there a better way?
6 Replies
Sander
Sanderβ€’16mo ago
That's exactly what i'm also looking for (but for packing slips instead)
BulkAction::make('download_packing_slips')
->label('Pakbonnen downloaden')
->action(function (Collection $records): void {
$invalidStatuses = ['new', 'onhold', 'cancelled'];

$invoiceIds = $records->reject(function ($record) use ($invalidStatuses) {
return in_array($record->status, $invalidStatuses);
})->map(function ($record) {
return optional($record->invoices()->where('type', 'debit')->latest()->first())->invoice_id;
})->filter()->implode(',');

$url = route('bulk.download.packing-slips', ['ids' => $invoiceIds]);

dd($url); // how to open this url in a new tab???
})
BulkAction::make('download_packing_slips')
->label('Pakbonnen downloaden')
->action(function (Collection $records): void {
$invalidStatuses = ['new', 'onhold', 'cancelled'];

$invoiceIds = $records->reject(function ($record) use ($invalidStatuses) {
return in_array($record->status, $invalidStatuses);
})->map(function ($record) {
return optional($record->invoices()->where('type', 'debit')->latest()->first())->invoice_id;
})->filter()->implode(',');

$url = route('bulk.download.packing-slips', ['ids' => $invoiceIds]);

dd($url); // how to open this url in a new tab???
})
LeandroFerreira
LeandroFerreiraβ€’16mo ago
BulkAction::make('customAction')
->action(function ($livewire, $records) {
$url = ''; //your custom url...
$livewire->js("window.open('{$url}', '_blank')");
})
BulkAction::make('customAction')
->action(function ($livewire, $records) {
$url = ''; //your custom url...
$livewire->js("window.open('{$url}', '_blank')");
})
Sander
Sanderβ€’16mo ago
Yep! thats working πŸ™‚ Thanks Leandro!
LeandroFerreira
LeandroFerreiraβ€’16mo ago
thanks Caleb actually πŸ˜…
Sander
Sanderβ€’16mo ago
Yeah, definitely!
LeandroFerreira
LeandroFerreiraβ€’16mo ago
@G3z if it works, close the topic please
Want results from more Discord servers?
Add your server