F
Filament2y ago
eazy

Redirect in listener

Hello, I'm making a custom listener to download a PDF when someone clicks on a button. The PDF gets generated on a URL so I want to redirect the user to the url when they click on the button. But it doesn't work. This is the current code:
$this->registerListeners(['repeater::downloadItem' => [
function (Repeater $component, string $statePath, string $idToDownload) {
if ($statePath !== $component->getStatePath()) {
return;
}

$record = $component->getRecord();
$id = Str::after($idToDownload, '-');

return redirect()->route('requests.pdf', [$record, false, [$id]]);
}
]]);
$this->registerListeners(['repeater::downloadItem' => [
function (Repeater $component, string $statePath, string $idToDownload) {
if ($statePath !== $component->getStatePath()) {
return;
}

$record = $component->getRecord();
$id = Str::after($idToDownload, '-');

return redirect()->route('requests.pdf', [$record, false, [$id]]);
}
]]);
4 Replies
Dan Harrin
Dan Harrin2y ago
listeners cant return like that unfortunately as there might be multiple listeners for the same event cant you just do this in javascript since you can pass the pdf url to that in the view
eazy
eazyOP2y ago
Yeah that should be possible too Thanks
awcodes
awcodes2y ago
You should be able to register a form action and return a StreamResponse that will download the file. I’m doing that in Curator.
eazy
eazyOP2y ago
Thanks for the tip 🙂
Want results from more Discord servers?
Add your server