yassilah / laravel-nova-nested-form

This package allows you to include your nested relationships' forms into a parent form.
240 stars 95 forks source link

Unable to create resource #81

Open BobbyBorisov opened 5 years ago

BobbyBorisov commented 5 years ago

Hey i am using Laravel Nova 2.3.0 and your latest version 3.0.4 but somehow when I try to create two nested objects like Questions has Answers, Answers has Categories it does not work. It says that it cannot save the form and gives me 422 error like following "answers[1][answer]: ["The answer field is required."], I am using the package with no customization. When i try to create just 1 question with 1 answer and 1 category for it, it works. but when there are 2 answers with 1 category each it gives me this error.

Is anybody else experiencing the same issue?

My code is below:

Nova\Question.php

public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('title'),
            Text::make('description'),
            NestedForm::make('Answers'),
        ];
    }

Models\Question.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Question extends Model
{
    public function answers()
    {
        return $this->hasMany(Answer::class);
    }
}

Nova\Answer.php

public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('text'),
            BelongsTo::make('Question'),
            NestedForm::make('Categories'),
        ];
    }

Models\Answer.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Answer extends Model
{
    public function question()
    {
        return $this->belongsTo(Question::class);
    }

    public function categories()
    {
        return $this->hasMany(Category::class);
    }
}

Nova\Category.php

public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('title'),
            BelongsTo::make('Answer'),
        ];
    }

Models\Category.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $table = 'categories';

    public function answer()
    {
        return $this->belongsTo(Answer::class);
    }
}
sohaibafifi commented 5 years ago

+1 the same here

BobbyBorisov commented 5 years ago

@sohaibafifi did you manage to fix it?

sohaibafifi commented 5 years ago

@sohaibafifi did you manage to fix it?

Not really. Looks like a dead project

mavericksthinker commented 5 years ago

@BobbyBorisov I have made a lot of customization and I am unknown of what are the changes made as I am not working with Nova recently. I dont manage this Nova package. But if I have time I will make a sample project solving this issue and hopefully that will help you.