Voyager: Multiple files problem [BUG]

Created on 13 Jun 2019  ·  4Comments  ·  Source: the-control-group/voyager

Version information

  • Laravel: v5.8
  • Voyager: v1.2.6
  • PHP: 7.3

Description

I added a custom field (multiple files) in the pages. I added files and saved. No problem, but when I want to attach a new file, old files remove

Steps To Reproduce

Steps to reproduce the behavior:

  1. Add custom field (multiple files) in the pages
  2. To attach a some files
  3. Save page
  4. Edit this record and try to attach files else
  5. Open again and you will see only new files

Screenshots

2019-06-13_17-46-02 (2)

Additional context

for fix you can change the method insertUpdateData()
vendor/tcg/voyager/src/Http/Controllers/Controller.php
insertUpdateData() { /* * merge ex_images and upload images */ if (($row->type == 'multiple_images' || $row->type == 'files') && !is_null($content)) { if (isset($data->{$row->field})) { $ex_files = json_decode($data->{$row->field}, true); if (!is_null($ex_files)) { $content = json_encode(array_merge($ex_files, json_decode($content))); } } } }

addressed possible bug

All 4 comments

Hey. Would you mind to make a PR with this solution?

i have this problem to. But you don't right. If you have the same problem, you need change "files" to "file" in your comment. So you get that:

if (($row->type == 'multiple_images' || $row->type == 'file') && !is_null($content)) {
if (isset($data->{$row->field})) {
$ex_files = json_decode($data->{$row->field}, true);
if (!is_null($ex_files)) {
$content = json_encode(array_merge($ex_files, json_decode($content)));
}
}
}

if you want solve the problem right now, you need:

  1. Change your config file config/voyager.php:

'controllers' => [
'namespace' => 'App\Http\Controllers\Voyager',
]

Then run php artisan voyager:controllers, Voyager will now use the child controllers which will be created at App/Http/Controllers/Voyager

  1. in file App\Http\Controllers\Voyager\VoyagerBaseController.php copy 3 functions:
    1) "update" from TCG\Voyager\Http\Controllers\VoyagerBaseController.php
    2) "store" form TCG\Voyager\Http\Controllers\VoyagerBaseController.php
    3) "insertUpdateData" from TCG\Voyager\Http\Controllers\Controller.php

  2. In file App\Http\Controllers\Voyager\VoyagerBaseController.php change function "insertUpdateData"
    change line

if ($row->type == 'multiple_images' && !is_null($content))

to

if (($row->type == 'multiple_images' || $row->type == 'file') && !is_null($content))

  1. Profit!

Hello! You can use type «File» to load multiple files, but bug in issue an exist in this method.I wrote step by step how you can fix problem without update Voyager.
 

Четверг, 14 ноября 2019, 6:46 +10:00 от Mikael Giacomini notifications@github.com:
 
Hi, I am not sure if this issue is related, probably not, but I cannot find the multiple files type at all in my bread:
Did I understand wrongly the meaning of the issue or it is something completely different? Sorry and thank you!

You are receiving this because you commented.
Reply to this email directly, view it on GitHub , or unsubscribe .
 
 
 
 

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

Was this page helpful?
0 / 5 - 0 ratings