F
Filament10mo ago
Youssef

iterate multiple actions in action group

I'm working on a project where has a submission that accepts multiple files with various file types, I'm trying add multiple buttons that represent files and when any of them is clicked this file is downloaded and these buttons should be grouped in an action group. Hence, I'm trying to add a function inside the action group that gets the files from the record then iterates on them so each file can have a button. But that doesn't seem to work due to ActionGroup:: not accepting a closure or an array with a closure inside. So initially I managed to create a single action that when clicked it fetches the links then redirects to a blade file which contains a JS code that manages to open each file in a new tab
Action::make('view_forms')
->label('View Forms')
->icon('heroicon-o-document')
->action(function (Submission $record) {
$mediaLinks = $record->getMedia('submission_forms')->map(function ($media) {
return $media->getFullUrl();
});

session()->put('mediaLinks', $mediaLinks);

return redirect('forms/redirect');

}),
Action::make('view_forms')
->label('View Forms')
->icon('heroicon-o-document')
->action(function (Submission $record) {
$mediaLinks = $record->getMedia('submission_forms')->map(function ($media) {
return $media->getFullUrl();
});

session()->put('mediaLinks', $mediaLinks);

return redirect('forms/redirect');

}),
Route::get('forms/redirect', function () {
$mediaLinks = session()->get('mediaLinks');
return view('redirects.redirect-pdf', [
'mediaLinks' => $mediaLinks
]);
})->middleware(['auth', 'verified']);
Route::get('forms/redirect', function () {
$mediaLinks = session()->get('mediaLinks');
return view('redirects.redirect-pdf', [
'mediaLinks' => $mediaLinks
]);
})->middleware(['auth', 'verified']);
<script>

let mediaLinks = @json($mediaLinks);

//used to open the media links in new tab
mediaLinks.map((link) => {
window.open(link, '_blank');
});

//redirect back to the previous page
setTimeout(() => {
window.location.href = '{{ redirect()->back()->getTargetUrl() }}';
}, 3000);

</script>
<title>Redirecting</title>
</head>
<body>
...
<script>

let mediaLinks = @json($mediaLinks);

//used to open the media links in new tab
mediaLinks.map((link) => {
window.open(link, '_blank');
});

//redirect back to the previous page
setTimeout(() => {
window.location.href = '{{ redirect()->back()->getTargetUrl() }}';
}, 3000);

</script>
<title>Redirecting</title>
</head>
<body>
...
1 Reply
Youssef
YoussefOP10mo ago
Please note that the files are stored via Spatie media library The other issue with the code i'm working with is that usually the user has to disable pop-up blocker in order to get the files too which inconvenient for some due to having pop-up blocker applied by default Any help please ?
Want results from more Discord servers?
Add your server