thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.78k stars 2.67k forks source link

Can't delete an Image of Multiple Images field #5578

Open ibnuhalimm opened 2 years ago

ibnuhalimm commented 2 years ago

Laravel version

6.20.44

PHP version

7.3.27

Voyager version

1.5.2

Database

MySQL 5.7.37

Description

I'm getting 500 error message "Invalid argument supplied for foreach()" while trying to delete an image of "multiple image" field.

[2022-04-14 06:19:51] production.ERROR: Invalid argument supplied for foreach() {"userId":9,"exception":"[object] (ErrorException(code: 0): Invalid argument supplied for foreach() at /var/www/html/application/vendor/tcg/voyager/src/Http/Controllers/VoyagerBaseController.php:757)
[stacktrace]
#0 /var/www/html/application/vendor/tcg/voyager/src/Http/Controllers/VoyagerBaseController.php(757): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'Invalid argumen...', '/var/www/html/a...', 757, Array)
#1 /var/www/html/application/vendor/tcg/voyager/src/Http/Controllers/VoyagerBaseController.php(746): TCG\\Voyager\\Http\\Controllers\\VoyagerBaseController->deleteBreadImages(Object(App\\Trip), Array, 'trips/April2022...')
...

Steps to reproduce

  1. Make a field as "multiple_images" at BREAD system
  2. Create new data
  3. Upload some images to these "multiple_images" field
  4. Edit the data
  5. Try to delete an image

Expected behavior

Response success, and image file should be deleted

Screenshots

image

Additional context

No response

ibnuhalimm commented 2 years ago

It says the error on Controllers/VoyagerBaseController.php on line 757.

...
       foreach ($rows as $row) {
            if ($row->type == 'multiple_images') {
                $images_to_remove = json_decode($data->getOriginal($row->field), true) ?? [];
            } else {
                $images_to_remove = [$data->getOriginal($row->field)];
            }

            foreach ($images_to_remove as $image) {
                // Remove only $single_image if we are removing from bread edit
...

I've checked that the $images_to_remove variable contains array data, but the error shows like the $images_to_remove is not an array.

ibnuhalimm commented 2 years ago

Maybe it's bug of php7.3