Giter Club home page Giter Club logo

Comments (14)

KevinKodamera avatar KevinKodamera commented on September 23, 2024 4

I've been looking into this issue and found it relates to how Nova requests get the resource (it uses the route).

I've made a patch for this that i hope can help the development of a fix.
It's based on the laravel-5.8 branch and needs some refactoring, at least when it comes to naming.

Here it is:
issue-41-patch.txt

Hope it helps!

from laravel-nova-nested-form.

yassilah avatar yassilah commented on September 23, 2024 3

hi all :)

sorry for the (very) late reply. I just released v2.1.0 that includes both @KevinKodamera's patch and should be compatible with both Nova 1 & 2 (no need for the 5.8 special branch). Could you confirm this works as expected?

from laravel-nova-nested-form.

KevinKodamera avatar KevinKodamera commented on September 23, 2024 2

Try running composer dump-autoload after applying the patch.

As for patches i recommend the cweagans/composer-patches package.

Then you can simply add the patch by adding the following to your composer.json file.
And it will (try to) apply the patch when running composer install or composer update.

  "extra": {
    "patches": {
      "yassi/nova-nested-form": {
        "Nested relations asks for required fields of parent": "https://github.com/yassipad/laravel-nova-nested-form/files/3085468/issue-41-patch.txt"
      }
    }
  }

from laravel-nova-nested-form.

alberto-bottarini avatar alberto-bottarini commented on September 23, 2024 1

Patch proposed by @KevinKodamera seems to work.
Could you please create a new tag version of this fantastic plugin?

Thanks a lot 🥇

from laravel-nova-nested-form.

yassilah avatar yassilah commented on September 23, 2024

Hi,

Can you also show me the Answer resource? Have you tried without the DuplicateField?

from laravel-nova-nested-form.

davidbonting avatar davidbonting commented on September 23, 2024

Removing DuplicateField in both Question and Answer does not solve the issue (exact same error).

<?php

namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Select;
use Jackabox\DuplicateField\DuplicateField;

class Answer extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = 'App\Answer';

    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'title';

    /**
     * The columns that should be searched.
     *
     * @var array
     */
    public static $search = [
        'id', 'title', 'value',
    ];

    /**
     * Get the fields displayed by the resource.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            BelongsTo::make('Question')
            ->searchable()
            ->rules('required'),

            Text::make('title')
            ->sortable()
            ->rules('required', 'max:255'),

            Text::make('value')
            ->sortable()
            ->rules('required', 'max:255'),

            Select::make('status')->options([
                '0' => 'System',
                '1' => 'User',
            ])
            ->displayUsingLabels()
            ->rules('required'),

            BelongsTo::make('Follow up', 'follow_up_question', 'App\Nova\Question')
            ->searchable()
            ->nullable(),

            DuplicateField::make('Duplicate')
            ->withMeta([
                'resource' => 'answers', // resource url
                'model' => 'App\Answer', // model path
                'id' => $this->id, // id of record
                'relations' => [] // an array of any relations to load (nullable).
            ]),
        ];
    }

    /**
     * Get the cards available for the request.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function cards(Request $request)
    {
        return [];
    }

    /**
     * Get the filters available for the resource.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function filters(Request $request)
    {
        return [];
    }

    /**
     * Get the lenses available for the resource.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function lenses(Request $request)
    {
        return [];
    }

    /**
     * Get the actions available for the resource.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function actions(Request $request)
    {
        return [];
    }
}

from laravel-nova-nested-form.

davidbonting avatar davidbonting commented on September 23, 2024

I'm sorry this does not solve my issue. But maybe I'm not knowing how to apply your fix correctly.

Composer

{
    "yassi/nova-nested-form": "dev-laravel-5.8"
}

Then apply your fix in:
vendor\yassi\nova-nested-form running git apply issue-41-patch.txt

This however give an error, saying I'm missing the files in src/Requests/*

So by adding empty files then applying you fix seems to work. Yet I do get the same error in Nova...

Thanks for your time anyways!

from laravel-nova-nested-form.

davidbonting avatar davidbonting commented on September 23, 2024

Thanks Kevin, this indeed does work!

@yassipad

from laravel-nova-nested-form.

davidbonting avatar davidbonting commented on September 23, 2024

Oke, I answered this a bit too quickly. Applying the patch seems to work, and after some changes in the Question and Answer Nova Resource it deed seem to work. But I'm stuck at the following error message when creating / updating answers:

{
  "messages" :  "The given data was invalid.",
  "errors" : {
    "answers[0][question]" : ["The question field is required."]
    }
}

This is probably caused by this in the answer resource:

BelongsTo::make('Question')
->searchable()
->rules('required'),

Removing that part will allow me to update answers, but when I try to create them I do get another error message (logic):

{
    "message": "SQLSTATE[HY000]: General error: 1364 Field 'question_id' doesn't have a default value (SQL: insert into `answers` (`title`, `value`, `status`, `follow_up`, `updated_at`, `created_at`) values (dd, aa, 0, 1, 2019-04-25 07:16:35, 2019-04-25 07:16:35))",
    "exception": "Illuminate\\Database\\QueryException",
    "file": "/var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
    "line": 664,
    ...
}

So instead of removing that part from the answer resource, I've added something:

BelongsTo::make('Question')
->searchable()
->rules('required')
->hideWhenUpdating(),

This again allows me to update Answers, but once I want to add a new one I get the first error message again (logic):

{
  "messages" :  "The given data was invalid.",
  "errors" : {
    "answers[0][question]" : ["The question field is required."]
    }
}

And I did try some more, but I'm always stuck at not being able to create a new answer. And also the above solutions are not feasible since you will remove the ability to create / update answers by "the normal Nova way"

from laravel-nova-nested-form.

Tahul avatar Tahul commented on September 23, 2024

#41 (comment)

I'm having the exact same issue; I've been digging through the code and watching the network & Vue devtools from Nova and it seems like it is sending empty GET parameters during the request: http://localhost:3001/nova-api/experiments/60?viaResource=&viaResourceId=&viaRelationship=

Which results in the parameter experiment_id from the relationship not being set.

from laravel-nova-nested-form.

rickdroce avatar rickdroce commented on September 23, 2024

#41 (comment)

I'm having the exact same issue; I've been digging through the code and watching the network & Vue devtools from Nova and it seems like it is sending empty GET parameters during the request: http://localhost:3001/nova-api/experiments/60?viaResource=&viaResourceId=&viaRelationship=

Which results in the parameter experiment_id from the relationship not being set.

I don't think the parameters are an issue, I've applied the patch provide by @KevinKodamera and everything works fine without the parameters. The problem is that it refer to the parent model when it is creating the children. This causes most of reported issues

from laravel-nova-nested-form.

rickdroce avatar rickdroce commented on September 23, 2024

v2.1.0 seems to work just as expected!
Thank you so much! 🎉

from laravel-nova-nested-form.

yassilah avatar yassilah commented on September 23, 2024

You're welcome, thanks so much for contributing :)

from laravel-nova-nested-form.

davidbonting avatar davidbonting commented on September 23, 2024

#67 (comment)

from laravel-nova-nested-form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.