Laravel-admin: Nested form with one-to-many relationships - ErrorException

Created on 25 May 2017  ·  3Comments  ·  Source: z-song/laravel-admin

Hi
I'm trying nested form:

class TestQuestion extends Model
{
    ...
    public function test()
    {
        return $this->belongsTo(Test::class);
    }
}
class Test extends Model
{
   ...
   public function testQuestions()
    {
    return $this->hasMany(TestQuestion::class);
    }
}
return Admin::form(Test::class, function (Form $form) {
   ...
   $form->hasMany('testQuestions', function (Form\NestedForm $form) {
       $form->text('text');
   });
});

I think I'm all right, but result is:

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

Am I doing anything wrong?

Many thanks for response.
abufalbo

Most helpful comment

Try lower case testquestions

class Test extends Model
{
   ...
   public function testquestions()
    {
    return $this->hasMany(TestQuestion::class, 'fid', 'id');
    }
}

All 3 comments

Try lower case testquestions

class Test extends Model
{
   ...
   public function testquestions()
    {
    return $this->hasMany(TestQuestion::class, 'fid', 'id');
    }
}

Super, it works.
Thanks.

Super, it works.
Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

piian picture piian  ·  3Comments

fokoz picture fokoz  ·  3Comments

zhenyangze picture zhenyangze  ·  3Comments

greentornado picture greentornado  ·  3Comments

daguye918 picture daguye918  ·  3Comments