laravel-nova-nested-form icon indicating copy to clipboard operation
laravel-nova-nested-form copied to clipboard

Unable to create resource

Open BobbyBorisov opened this issue 5 years ago • 4 comments

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);
    }
}

BobbyBorisov avatar Sep 18 '19 19:09 BobbyBorisov

+1 the same here

sohaibafifi avatar Oct 23 '19 10:10 sohaibafifi

@sohaibafifi did you manage to fix it?

BobbyBorisov avatar Nov 13 '19 09:11 BobbyBorisov

@sohaibafifi did you manage to fix it?

Not really. Looks like a dead project

sohaibafifi avatar Nov 13 '19 18:11 sohaibafifi

@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.

mavericksthinker avatar Nov 14 '19 02:11 mavericksthinker