How to specify upload path on file repeatable #1295
Replies: 2 comments
-
|
To specify the upload path for files within a repeatable field in Laravel Backpack, you need to make some adjustments to your field definition and handle the file upload in your model. Here's how you can modify your code to achieve this:
CRUD::addField([
// ... other field properties ...
'fields' => [
// ... other subfields ...
[
'name' => 'files',
'label' => __('backend/process-area.attachments'),
'type' => 'upload_multiple',
'upload' => true,
'wrapper' => ['class' => 'form-group col-md-12'],
'disk' => 'uploads',
'path' => 'documents/process_2/notes', // Specify the path here
],
],
// ... other field properties ...
]);
public function setFilesAttribute($value)
{
$attribute_name = "files";
$disk = "uploads";
$destination_path = "documents/process_{$this->id}/notes";
$this->uploadMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path);
}This approach is based on the information provided in the Github Issue: Can't upload file on disk and Github Issue: [Bug] Upload subfield contains wrong url in repeteable relationship field. Note that you'll need to replace Also, make sure that the Remember that the If you encounter any issues with the file URLs after implementing this, you might need to adjust the URL generation in your views or use Laravel's ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️ Relevant sources: Github Issue (closed): Can't upload file on disk |
Beta Was this translation helpful? Give feedback.
-
|
Hey @cod3rshotout Generally, You can configure the disk & folder path in uploaders like this: [
'name' => 'files',
'type' => 'upload_multiple',
'withFiles' => [
'disk' => 'public', // the disk where file will be stored
'path' => 'uploads', // the path inside the disk where the file will be stored
]
],And for Naming files when using Uploaders, you can: CRUD::field('avatar')->type('upload')->withFiles([
'fileNamer' => \Backpack\CRUD\app\Library\Uploaders\Support\FileNameGenerator::class,
]);
// alternativelly you can pass a closure:
->withFiles([
'fileNamer' => function($file, $uploader) { return 'the_file_name.png'; },
])But your path Feel free to re-open it if I missed something. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have created a repeater field in Laravel Backpack as follows: php Copia Modifica
I am trying to save the uploaded files to the following path: uploads/documents/process_2/notes, where 2 is the reference ID of the entity. How can I correctly handle file uploads within the repeater field and ensure they are stored in the correct path?
This is the filesystem config:
Beta Was this translation helpful? Give feedback.
All reactions