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

Global search is broken, when using NestedForm

Open bernhardh opened this issue 3 years ago • 4 comments

I have a resource User with a nested Form Posts, just like the example in the documentation:

NestedForm::make('Posts', 'posts', \App\Nova\Post::class)

Now, the global search is broken, since the API (/nova-api/search?search=test) returns a 404 error instead of the json result. Commenting out the nested form and everything works as expected.

The relation itself work. When I add the HasMany field (and leave the NestedForm commented out), everything still works as expected:

HasMany::make("Posts", "posts",  \App\Nova\Post::class),

bernhardh avatar Jan 13 '21 17:01 bernhardh

i have the same issue. Did you manage to fix it or have a workaround?

GewoonRoy avatar Apr 08 '21 11:04 GewoonRoy

Nope. I haven't fixed this issue yet.

bernhardh avatar Apr 08 '21 13:04 bernhardh

The problem is in src/NestedForm.php:200 which got introduced in commit 0905cca77736cd7bdfcea6d86229af95e9f81945 . I'm not sure what it actually does, but latest Nova seems to work without it.

skywalker666 avatar Sep 06 '21 13:09 skywalker666

By adding a condition before src/NestedForm.php:200 line, the search is working again :

// Added this condition, so the error doesn't occur when the request is a GlobalSearchRequest
if(get_class(app(NovaRequest::class)) !== "Laravel\Nova\Http\Requests\GlobalSearchRequest") 
     $this->resolve(app(NovaRequest::class)->model());

Did a PR

tomheno avatar Feb 07 '22 01:02 tomheno