F
Filament15mo ago
javif89

File upload in actions

Hey guys, I have a question that I couldn't really find an answer for in the docs. I have a model with a form where you can upload an image, all of that works great. Now I'm trying to add a "Bulk upload" action that lets the user upload multiple files and it will create a new record for each file uploaded with some other fields filled out based on the file name. I have the action set up but it's a bit unclear to me how to save the files.
->action(function (array $data) {
$records = [];

foreach ($data['original_file_name'] as $filename => $original) {
$name = Str::from($original)->before('.')->trim()->lower()->replace(' ', '_')->toString();
$records[] = [
'image_path' => $filename,
'category_id' => $data['category_id'],
'name' => $name,
];
}
})
->action(function (array $data) {
$records = [];

foreach ($data['original_file_name'] as $filename => $original) {
$name = Str::from($original)->before('.')->trim()->lower()->replace(' ', '_')->toString();
$records[] = [
'image_path' => $filename,
'category_id' => $data['category_id'],
'name' => $name,
];
}
})
This is what I have so far. I'm just not sure how to save the files from here. Would appreciate any help.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server