epartment / nova-dependency-container

A Laravel Nova field container allowing to depend on other fields values
MIT License
382 stars 163 forks source link

Problem with hasMany #101

Open alberto-bottarini opened 4 years ago

alberto-bottarini commented 4 years ago

I have a nova resource configuration like this:

NovaDependencyContainer::make([
    HasMany::make('CourseEditions', 'courseEditions', CourseEdition::class),
])->dependsOn('type', 'ad-edizioni'),

NovaDependencyContainer::make([
    HasMany::make('CourseLevelEditions', 'courseLevelEditions', CourseLevelEdition::class),
])->dependsOn('type', 'a-livelli'),

I would like to show a HasMany panel only if type field matches a defined value.

It works well, but when i click on Create button inside this panel, I got a 404 error on this URL: /nova-api/id/field/courseEditions i guess because Nova cannot find HasMany field because it is wrapped by NovaDependecyContainer.

UPDATE

I solved hacking in this way:

NovaDependencyContainer::make([
    HasMany::make('CourseEditions', 'courseEditions', CourseEdition::class),
])->dependsOn('type', 'ad-edizioni'),

NovaDependencyContainer::make([
    HasMany::make('CourseLevelEditions', 'courseLevelEditions', CourseLevelEdition::class),
])->dependsOn('type', 'a-livelli'),

HasMany::make('CourseEditions', 'courseEditions', CourseEdition::class)
    ->hideFromIndex()
    ->hideFromDetail()
    ->hideWhenCreating()
    ->hideWhenUpdating(),
HasMany::make('CourseLevelEditions', 'courseLevelEditions', CourseLevelEdition::class)
    ->hideFromIndex()
    ->hideFromDetail()
    ->hideWhenCreating()
    ->hideWhenUpdating(),

Basically I created standard but hidden HasMany fields

wize-wiz commented 4 years ago

@alberto-bottarini I'll test this myself when I have some more time to handle all the issues. This does seem weird though.

robindrost commented 4 years ago

Any update on this issue? Having the same problem with a hasMany field. It work with an extra hidden hasMany field as suggested by @alberto-bottarini.

alberto-bottarini commented 4 years ago

Any news?

danielfaulknor commented 3 years ago

I get a 409 with a HasMany inside the container when I try to view the resource unless I use the hack mentioned above but the layout is not quite right. Nova 3.28.0 and Laravel 8.54