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

defining the inverse - Whats's wrong?

Open Muetze42 opened this issue 4 years ago • 2 comments

I've following One To Many Relation:

    /**
     * Get the steps for the recipe.
     */
    public function steps(): HasMany
    {
        return $this->hasMany(Step::class);
    }
    /**
     * Get the recipe that owns the step.
     */
    public function recipe(): BelongsTo
    {
        return $this->belongsTo(Recipe::class);
    }

And in my recipe resource this package:

NestedForm::make('steps'),

But, if I want to create a new entry, I get this message: A field defining the inverse relationship needs to be set on your related resource (e.g. MorphTo, BelongsTo, BelongsToMany...)

Where should the error be or does the package have a different idea of a relation than me and the Laravel documentation?

Muetze42 avatar Jul 01 '21 20:07 Muetze42

You need to add the following line to fields list in your Nova/Steps resource.

    public function fields(Request $request)
    {
        return [
            ID::make(__('ID'), 'id')->sortable(),

            BelongsTo::make('recipe'),
        ];
    }

cserepesmark avatar Jul 27 '21 16:07 cserepesmark

After defining the inverse relationship it is showing relationship column. Can i hide some how?

image

itscoolprakhar avatar Dec 25 '22 10:12 itscoolprakhar