orlyapps / nova-belongsto-depend

Larave Nova BelongsTo Field with Dependcy
MIT License
182 stars 65 forks source link

Making a NovaBelongsToDepend field not required #15

Closed lvdhoorn closed 5 years ago

lvdhoorn commented 5 years ago

As far as i can see it is not possible to make a field not required.

For example we have the following fields: NovaBelongsToDepend::make('Week') ->options(\App\Week::where('year', '=', date('Y'))->get()), NovaBelongsToDepend::make('Country', 'Country', '\App\Nova\Country') ->optionsResolve(function ($week) { return $week->countries()->get(); }) ->dependsOn('Week')

A week field is a required field for us but a country field is not.

It would be really great if we can make a depended field optional.

noahlocke commented 5 years ago

@orlyapps just discovered this one myself, kind of a deal breaker... any chance we can patch this up?

noahlocke commented 5 years ago

@lvdhoorn I think this was actually a bug with Nova. The latest release, 1.1.7, added in support for nullable() BelongsTo fields. This is working for me:

                NovaBelongsToDepend::make('Consumer', 'client', \App\Nova\Client::class)
                    ->optionsResolve(function ($user) {
                        return $user->clients;
                    })
                    ->dependsOn('User')
                    ->onlyOnForms()
                    ->nullable()
orlyapps commented 5 years ago

@lvdhoorn thanks. I will close this issue then.