kirschbaum-development / nova-inline-relationship

A package to present relationships as inline properties in Nova.
MIT License
196 stars 84 forks source link

Issue with Saving Stakeholdrers #117

Closed HeadStudios closed 8 months ago

HeadStudios commented 1 year ago

I am getting the following error when trying to save my Contact model after adding some Stakeholder inline rows:

2023-03-29 11:53:51] local.ERROR: App\Nova\Contact::fields(): Argument #1 ($request) must be of type Laravel\Nova\Http\Requests\NovaRequest, Illuminate\Http\Request given, called in /var/www/vendor/kirschbaum-development/nova-inline-relationship/src/Observers/NovaInlineRelationshipObserver.php on line 97 {"userId":1,"exception":"[object] (TypeError(code: 0): App\Nova\Contact::fields(): Argument #1 ($request) must be of type Laravel\Nova\Http\Requests\NovaRequest, Illuminate\Http\Request given, called in /var/www/vendor/kirschbaum-development/nova-inline-relationship/src/Observers/NovaInlineRelationshipObserver.php on line 97 at /var/www/app/Nova/Contact.php:66) [stacktrace] Full stack trace: https://gist.github.com/HeadStudios/b1025e883ba300504745561875e267df

Here is how my Contact nova resource is structured: https://gist.github.com/HeadStudios/e3bb5bfb2eb37341f9b7e4e091ed4ab5

Stakeholder Resource for what it's worth: https://gist.github.com/HeadStudios/d7bb36fbe949c2b8ae0b7df2cc828a43

Video for context: https://share.getcloudapp.com/o0uYekNE

Update: this has been fixed by updating getModelRelationships() function to the following:

protected function getModelRelationships(Model $model) { return collect(Nova::newResourceFromModel($model)->fields(\Laravel\Nova\Http\Requests\NovaRequest::createFrom(request()))) ->flatMap(function ($value) { return Integrate::fields($value); }) ->filter(function ($value) { return $value->component === 'nova-inline-relationship'; }) ->pluck('attribute') ->all(); }