CRUD: [Bug] disabling ConvertEmptyStringsToNull has side effects on the saving process for M-M relations
Bug report
What I did
I have a select2_from_ajax_multiple which represent n-n relationship and this field is optional but when I try to submit the form without filling the field it crashes
What I expected to happen
the record should be saved and the relation should be empty
What happened
it crashes array_values() expects parameter 1 to be array, null given

What I’ve already tried to fix it
after some investigation I found that the issue happens because the form is sending empty string when the field is empty so in app/Library/CrudPanel/Traits/Create.php the null escapes doesn’t work I suggest to make it like so $values = (isset($relationDetails['values'][$relationMethod]) && !empty($relationDetails['values'][$relationMethod])) ? $relationDetails['values'][$relationMethod] : []; that way wether the value is null or the value is empty it becomes []
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:
PHP VERSION:
PHP 7.4.21 (cli) (built: Sep 30 2021 13:37:02) ( NTS ) Copyright © The PHP Group Zend Engine v3.4.0, Copyright © Zend Technologies with Xdebug v2.9.8, Copyright © 2002-2020, by Derick Rethans
LARAVEL VERSION:
v8.83.19@4264f2ee12330bdb1be050998f58ba7271236395
BACKPACK VERSION:
5.1.4@4539c787a2e052d2e2e2c00188c38432dc2a7ea9
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19 (19 by maintainers)
@pxpm yes I agree with you that this is a very useful Middleware and I always leave it on but unfortunately the system that I’m working on the DB design is a bit weird that some columns are not nullable that’s why we disabled it
Anyways the PR is updated now, thank you for your time and effort regarding this and sorry to discover this just now