Youssef
Youssef
FFilament
Created by Youssef on 3/5/2024 in #❓┊help
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>
...
4 replies