You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I keep getting errors when using a subfield that has a "withfiles" configuration. This is the setup:
There is a model with its "pdfs" attribute as a repeatable field in the Crud model
The repeatable field has two subfields: title (text field), and file (upload field, which has the withFiles config)
The model has an additional "links" attribute, which is a repeatable field with only a text and url field
Both the pdfs and links attributes are cast as array on the parent model
When I create a new entry, all is fine, regardless of whether I add entries to the pdf repeatable element.
When I then go to edit that entry, regardless of whether I add, remove, or leave empty the pdf repeatable field, on save, I get the following error:
array_map(): Argument #2 ($array) must be of type array, string given
I also noticed that after the first save, if I leave both repeatable fields empty, the "pdfs" field is saved as "[]" in the database, whereas the links field is NULL, which already seemed like a weird difference.
Now, in src/app/Library/Uploaders/Support/Traits/HandleRepeatableUploads.php on line 153, I found the following code which causes the error:
If $values is null to begin with, then this throws an error because it never because it never becomes the array that array_map expects it to be. An easy fix is to change line 154 to:
But this may cause other issues, I'm not sure. I also expected this error would already be impossible because the attribute is cast as an array on the parent model, but apparently not for some reason. Not sure if there is any code related to repeatable fields or uploads within that prevents the model casts to work?
What I expected to happen
Be able to use withfiles inside repeatable element
What happened
I got an error on update
What I've already tried to fix it
I can confirm that when I remove the "withFiles" field from the equation for the PDFs field as well, behavior reverts to be the same as the links field and no more errors are thrown.
Is it a bug in the latest version of Backpack?
After I run composer update backpack/crud the bug... is it still there?
Yes
Backpack, Laravel, PHP, DB version
When I run php artisan backpack:version the output is:
Hi @cod3rshotout! Not really... For now I'm just overwriting the HandleRepeatableUploads trait locally. I just copied the whole file and have changed line 154 as described in my original post. This hasn't caused any other issues so far, but as I also said in the original post: it may lead to other issues in other configurations than in my specific use case.
Bug report
What I did
I keep getting errors when using a subfield that has a "withfiles" configuration. This is the setup:
When I create a new entry, all is fine, regardless of whether I add entries to the pdf repeatable element.
When I then go to edit that entry, regardless of whether I add, remove, or leave empty the pdf repeatable field, on save, I get the following error:
array_map(): Argument #2 ($array) must be of type array, string given
I also noticed that after the first save, if I leave both repeatable fields empty, the "pdfs" field is saved as
"[]"
in the database, whereas the links field isNULL
, which already seemed like a weird difference.Now, in
src/app/Library/Uploaders/Support/Traits/HandleRepeatableUploads.php
on line 153, I found the following code which causes the error:If $values is null to begin with, then this throws an error because it never because it never becomes the array that
array_map
expects it to be. An easy fix is to change line 154 to:$values = is_string($values) ? json_decode($values, true) : (array)$values;
But this may cause other issues, I'm not sure. I also expected this error would already be impossible because the attribute is cast as an array on the parent model, but apparently not for some reason. Not sure if there is any code related to repeatable fields or uploads within that prevents the model casts to work?
What I expected to happen
Be able to use withfiles inside repeatable element
What happened
I got an error on update
What I've already tried to fix it
I can confirm that when I remove the "withFiles" field from the equation for the PDFs field as well, behavior reverts to be the same as the links field and no more errors are thrown.
Is it a bug in the latest version of Backpack?
After I run
composer update backpack/crud
the bug... is it still there?Yes
Backpack, Laravel, PHP, DB version
When I run
php artisan backpack:version
the output is:The text was updated successfully, but these errors were encountered: