[Bug] Version 4.1.52 broke inline_create
See original GitHub issueBug report
What I did
Defined a field to use inline_create with:
$this->crud->addField([
'type' => 'relationship',
'name' => 'customer_id',
'label' => 'Customer',
'ajax' => true,
'inline_create' => true,
]);
What I expected to happen
The field was working normally before updating to Backpack version 4.1.53, showing the button to open the modal and create the related model.
What happened
In the “create operation”, even though there is no value in the field, the file fetch_or_create tries to get a value from the database passing an empty string as the $current_value on line 37.
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "" (SQL: select * from "customers" where "id" = ) (View: vendor/backpack/crud/src/resources/views/crud/fields/relationship/fetch_or_create.blade.php)
What I’ve already tried to fix it
Commenting the ajax and inline_create attributes stops the error.
I believe what caused this was a change from PR #3671 that changed to a strict comparison of $current_value and false.
When the field is empty, the previous line sets the empty string as the value for $current_value.
Before the change, since it was a loose comparison, the code would not try to access the database inside the if block.
PHP VERSION:
PHP 7.4.3 (cli) (built: Aug 13 2021 05:39:12) ( NTS ) Copyright © The PHP Group Zend Engine v3.4.0, Copyright © Zend Technologies with Zend OPcache v7.4.3, Copyright ©, by Zend Technologies
LARAVEL VERSION:
v8.61.0@3d528d3d3c8ecb444b50a266c212a52973a6669b
BACKPACK VERSION:
4.1.53@8698b8ed51e8b18e311f928f6f80a7161f1eb172
DATABASE VERSION:
PostgreSQL 12.7
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)

Top Related StackOverflow Question
Hello @matheusb-comp
Thanks for the report.
I can confirm that this happens ONLY in PostGres! MySQL would not complain from such query:
select * fromiconswhereid= ''this would just return empty result from MySQL. But in PG it would throw that error.I am working on a fix for it, I should get back to you guys in a moment here. Just write it down so @promatik don’t lose time here debugging!
Best, Pedro
You are welcome and thanks for getting back with the feedback.
Sorry for introducing the bug, If you were not using PG I am sure I would not notice it in the near future!
Glad we could workout the solution. You are happy, we are happy, future users would be happy! Win-Win-Win!
Best, Pedro