alexwenzel / nova-dependency-container

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

BelongsTo not populated inside DependencyContainer #16

Closed makkinga closed 1 year ago

makkinga commented 1 year ago

This is more a question than an actual issue. I have a BelongsTo field inside a DependencyContainer that is not being populated. I can think of reasons why this happens, but I don't know if what I want is even possible with this setup or if I'm doing it wrong. I can't seem to find anything on this in the documentation.

This is the code I'm using:

DependencyContainer::make([
    BelongsTo::make(__('Group Parent'), 'variantOf', Product::class)->required(true),
])->dependsOn('type', 'variant')
makkinga commented 1 year ago

Nvm, while tinkering with my code I stumbled on this. Apparently, that's a thing and I can fix it like this:

BelongsTo::make(__('Group Parent'), 'variantOf', Product::class)
    ->required(true)
    ->hide()
    ->dependsOn('type', function (BelongsTo $field, NovaRequest $request, FormData $formData) {
        if ($formData->type === 'variant') {
            $field->show();
        }
    }),

Sorry for wasting your time! hopefully, this helps someone else reading this 😅