Laravel-admin: Relationship with camel case name cause exception on edit form with hasMany field

Created on 30 Jun 2017  ·  4Comments  ·  Source: z-song/laravel-admin

Let's say I have a relationship invoiceLines used in form with the hasMany field, the creation form works perfectly (database proves it), but when editing the form, I get this error:

ErrorException In HasMany.php line 359 :
Invalid argument supplied for foreach() (View: C:\xampp\htdocs\laravel-admin\vendor\encore\laravel-admin\views\form.blade.php)

With the following form snippet

$form->hasMany('invoiceLines', function(Form\NestedForm $form) {
    $form->decimal('amount');
    $form->number('quantity');
});
wontfix

Most helpful comment

It is seems to work if I put all the relationship name all in lowercase
$form->hasMany('invoicelines', ...

While keeping the relationship in my model camel-cased.

I still think it could be looked into because it can lead to mistakes and maybe hiding other bugs...

All 4 comments

It is seems to work if I put all the relationship name all in lowercase
$form->hasMany('invoicelines', ...

While keeping the relationship in my model camel-cased.

I still think it could be looked into because it can lead to mistakes and maybe hiding other bugs...

Same thing happens with $form->multipleSelect()
It silently fails (no error or exception), not saving and losing the pivot data.
Setting the field name in lowercase fixes the problem.

@isometriq I had the same issue with camel cased relationships in nested forms, your solution worked. Thanks

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdhraesaemer picture cdhraesaemer  ·  3Comments

vlongen picture vlongen  ·  3Comments

zhenyangze picture zhenyangze  ·  3Comments

MarKco picture MarKco  ·  3Comments

xiaalngf picture xiaalngf  ·  3Comments