Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.04k stars 885 forks source link

[Bug] Uploaded files cannot be deleted #5411

Closed misiekch closed 7 months ago

misiekch commented 8 months ago

Bug report

What I did

I am using upload_multiple field with default MultipleFiles uploader.

What I expected to happen

I wanted to delete uploaded files.

What happened

Files were not deleted.

What I've already tried to fix it

3 weeks ago (on Dec 8) @pxpm committed changes to MultipleFiles.

According to fix uploaders in repeatable relationships

Line $filesToDelete = CRUD::getRequest()->get('clear_'.$this->getName()); was replaced with $filesToDelete = collect(CRUD::getRequest()->get('clear_'.$this->getRepeatableContainerName() ?? $this->getName()))->flatten()->toArray();

The problem is that 'clear_'.$this->getRepeatableContainerName() ?? $this->getName() returns clear_ when $this->getRepeatableContainerName() returns null.

Is it a bug in the latest version of Backpack?

After I run composer update backpack/crud the bug... is it still there?

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 8.2.9 (cli) (built: Aug 16 2023 13:30:34) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.9, Copyright (c) Zend Technologies with Zend OPcache v8.2.9, Copyright (c), by Zend Technologies

LARAVEL VERSION:

10.37.3.0

BACKPACK PACKAGE VERSIONS:

backpack/activity-log: 2.0.1 backpack/basset: 1.2.2 backpack/crud: 6.4.2 backpack/generators: v4.0.2 backpack/permissionmanager: 7.1.1 backpack/pro: 2.0.20 backpack/settings: 3.1.0 backpack/theme-tabler: 1.1.2

karandatwani92 commented 7 months ago

Hey @misiekch sorry for the trouble.

Hey @pxpm I did the following to test and can confirm the delete has stopped working: GIF ѻ GIF

CRUD::column([
    'name'      => 'photos',
    'label'     => 'Photos',
    'type'      => 'upload_multiple',
    'withFiles' => true
]);
protected function setupDeleteOperation()
{
   CRUD::field('photos')->type('upload')->withFiles();
}
pxpm commented 7 months ago

Hey @misiekch thanks for the report 🙏

Thank you also @karandatwani92 for the test and heads up 🙏

I've fixed this in 6.5.1, please let me know if you guys are still experiencing issues.

Cheers and happy new year 🥳