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

BadMethodCallException: Method Illuminate\Database\Query\Builder::getData does not exist.

Open BryanMootoosamy opened this issue 5 years ago • 2 comments

Hello, I use your package to manage accounts and companies (so I'm able to create a company from a account and link the company to the account). Since I've upgraded to laravel 5.8, I experience this error :

Method Illuminate\Database\Query\Builder::getData does not exist.

when adding a new company (the nested form) to the account (the ressource).

BryanMootoosamy avatar Mar 12 '19 07:03 BryanMootoosamy

The current release is not compatible with Nova 2/Laravel 5.8, please use the laravel-5.8 branch.

composer require yassi/nova-nested-form:dev-laravel-5.8

yassilah avatar Mar 12 '19 09:03 yassilah

Solution

File: FillsSubAttributes.php Method: runNestedOperations(NovaRequest $request, string $attribute, Model $model) Line: 223 (phpstorm) Bug: $this->touched[] = $value->getData()->id

Triggers Bug

    protected function runNestedOperations(NovaRequest $request, string $attribute, Model $model)
    {
        $data = $request->{$attribute} ?? null;

        if (is_object($data) || is_array($data)) {
            foreach ($data as $index => $value) {

                if (!is_int($index)) {
                    $value = $request->{$attribute};
                    $index = null;
                }

                $this->runNestedOperation($value, $model, $attribute, $index, $request);

                if ($value instanceof Response) {
                    abort($value->getStatusCode());
                }

                $this->touched[] = $value->getData()->id;

                if (is_null($index)) {
                    break;
                }
            }
        } else {
            $this->shouldRemoveAll = true;
        }

        return $this;
    }

Solves Bug

    protected function runNestedOperations(NovaRequest $request, string $attribute, Model $model)
    {
        $data = $request->{$attribute} ?? null;

        if (is_object($data) || is_array($data)) {
            foreach ($data as $index => $value) {

                if (!is_int($index)) {
                    $value = $request->{$attribute};
                    $index = null;
                }

                $this->runNestedOperation($value, $model, $attribute, $index, $request);

                if ($value instanceof Response) {
                    abort($value->getStatusCode());
                }

                $this->touched[] = $value->id;

                if (is_null($index)) {
                    break;
                }
            }
        } else {
            $this->shouldRemoveAll = true;
        }

        return $this;
    }

zhorton34 avatar Mar 29 '19 19:03 zhorton34