Wayne_Swart
Wayne_Swart
FFilament
Created by Wayne_Swart on 1/24/2024 in #❓┊help
Use resource record ID in file upload path
Wow, thank you Matthew. I was over complicating it, your solution does indeed work.
9 replies
FFilament
Created by Wayne_Swart on 1/24/2024 in #❓┊help
Use resource record ID in file upload path
That's a great idea, thanks. Let me see if I can use that way. Thank you!
9 replies
FFilament
Created by Wayne_Swart on 1/24/2024 in #❓┊help
Use resource record ID in file upload path
I am not yet going to mark this post as solved, since I would like to know if there isn't another easier way to do this. Thanks.
9 replies
FFilament
Created by Wayne_Swart on 1/24/2024 in #❓┊help
Use resource record ID in file upload path
So, here is my solution using the mutateFormDataBeforeCreate() function when the form is submitted. It is based off of another user's code. It's not pretty, but it does work:
protected function mutateFormDataBeforeCreate(array $data): array
{
if (is_array($data['attachments'])) {

// Get the next auto increment from the database.
$nextAutoIncrement = Claim::getModel()::max('id') + 1;

foreach ($data['attachments'] as $key => $value) {
// Move the uploaded files from the temporary storage to the public storage.
Storage::disk('public')->move( $value, 'claim-attachments/' . $nextAutoIncrement . '/' . str_replace('claim-attachments/','', $value));

// Change the file path to be the next auto increment.
$data['attachments'][$key] = 'claim-attachments/' . $nextAutoIncrement . '/' . str_replace('claim-attachments/','', $value);
}
}
return $data;
}
protected function mutateFormDataBeforeCreate(array $data): array
{
if (is_array($data['attachments'])) {

// Get the next auto increment from the database.
$nextAutoIncrement = Claim::getModel()::max('id') + 1;

foreach ($data['attachments'] as $key => $value) {
// Move the uploaded files from the temporary storage to the public storage.
Storage::disk('public')->move( $value, 'claim-attachments/' . $nextAutoIncrement . '/' . str_replace('claim-attachments/','', $value));

// Change the file path to be the next auto increment.
$data['attachments'][$key] = 'claim-attachments/' . $nextAutoIncrement . '/' . str_replace('claim-attachments/','', $value);
}
}
return $data;
}
9 replies
FFilament
Created by Wayne_Swart on 1/24/2024 in #❓┊help
Use resource record ID in file upload path
There is a mutateFormDataBeforeCreate() method you can call in the create page, but the attachments seem to be empty in the posted array, since they are uploaded in realtime. So I could get it to work on the edit page, but not during create. A workaround could potentially be to hide the file attachments during creation and only show it on the edit page. Is something like that possible? As amazing as filament is, I feel there are a lot of hacking needed in order to get basic things done unfortunately ;/
9 replies
FFilament
Created by Wayne_Swart on 1/16/2024 in #❓┊help
Multiple select filter does not reload
Thanks, I will make sure I am on the latest version
5 replies