Is there a way to use upload multiple for a 1-n relationship? Please help me #791
-
Hi, i want to upload multiple file for a 1-n relationship. public function filePath()
{
return $this->hasMany(ArticleFile::class, 'article_id');
} In ArticleFile Model public function setFilePathAttribute($value)
{
$attribute_name = 'file_path';
$disk = 'upload';
$destination_path = '/storage/app/uploads/articles/' . Carbon::now()->format('Ym');
$this->uploadMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path);
} In ArticleController CRUD::addField([
'name' => 'file_path',
'type' => 'upload_multiple',
'label' => '本文ファイル',
'disk' => 'upload',
'upload' => true,
]) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @tatvn You can't use the If the relationship is important: You can use https://backpackforlaravel.com/docs/6.x/crud-uploaders#uploaders-for-spatie-medialibrary 👆This associates all sorts of files with Eloquent models OR You can use relationship subfields(title, upload), try these steps and let me know if they help!
OR You can create a custom field using existing OR Create a few accessor & mutator combos which turn JSON and save the values to a related table. |
Beta Was this translation helpful? Give feedback.
Hey @tatvn
You can't use the
upload_multiple
field for a 1-n relationship. It stores the values as a JSON array in the database column.If the relationship is important:
You can use https://backpackforlaravel.com/docs/6.x/crud-uploaders#uploaders-for-spatie-medialibrary
👆This associates all sorts of files with Eloquent models
OR
You can use relationship subfields(title, upload), try these steps and let me know if they help!