F
Filament15mo 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 Harrin15mo 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
eazy15mo ago
Yeah that should be possible too Thanks
awcodes
awcodes15mo 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
eazy15mo ago
Thanks for the tip 🙂