Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HasMany field in fieldsForDetail() will give 404 error when attempt to create #5749

Closed
magdicom opened this issue Jul 26, 2023 · 5 comments
Closed
Assignees
Labels
bug Verified bug by the Nova team

Comments

@magdicom
Copy link

magdicom commented Jul 26, 2023

  • Laravel Version: 10.16.0
  • Nova Version: 4.23.0
  • PHP Version: 8.2.8

Description:

I'm using Resource::fieldsForDetail to display certain fields different from what is displayed in index and update resource form.
when defining the relationship field HasMany inside the Resource::fieldsForDetail method the table will load normally, but the problem is when I click the Create XX button above this relationship table it will keeps loading and it will return a 404 error page at the logs.

The fix:
after hours of tweaking this I figured it could only work if the same relationship field is defined in the fields method, even if its hidden.

Detailed steps to reproduce the issue on a fresh Nova installation:

to reproduce this error you simply need to define a HasMany field in one resources' fieldsForDetail:

// following the example given in docs: https://nova.laravel.com/docs/4.0/resources/relationships.html#hasmany

class User extends Resource
{
    public function fields(NovaRequest $request)
    {
        return [
            Text::make('Name'),
        ];
    }

    public function fieldsForDetail(NovaRequest $request)
    {
        return [
            HasMany::make('Posts'),
        ];
    }
}

the example above wont work when you try to create a new post from inside user details page.

@crynobone
Copy link
Member

This PR has been reverted, please add HasMany field to fieldsForCreate() or fields() if you need to use this structure.

@sentq
Copy link

sentq commented Aug 2, 2023

@crynobone what you say actually is that I'm forced to use fields() at all cases and I cannot specify fields in different methods like fieldsForDetails and fieldsForIndex!

@crynobone
Copy link
Member

I would recommend using fields() and only uses dynamic fields for further customisation. Internally for relations checking we would prefer to filters all dynamic fields to avoid false positive and avoid performance penalty when we need to check if the field actually exists in a resource.

@magdicom
Copy link
Author

magdicom commented Aug 2, 2023

I see your point, but I wish you would reconsider this even later.

also if this can be mentioned in the docs it would be very time savior.

Thanks!

@github-actions
Copy link

github-actions bot commented Aug 8, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Verified bug by the Nova team
Projects
None yet
Development

No branches or pull requests

2 participants