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

Use BelongsTo inside NovaDependencyContainer #193

Open
daugaard47 opened this issue Nov 18, 2021 · 2 comments
Open

Use BelongsTo inside NovaDependencyContainer #193

daugaard47 opened this issue Nov 18, 2021 · 2 comments

Comments

@daugaard47
Copy link

1. If I do this:

                Select::make('Description Type', 'description_type')->options([
                        0 => 'Default Description',
                        1 => 'Country Specific Description',
                        2 => 'Destination Specific Description',
                ])->displayUsingLabels(),

                NovaDependencyContainer::make([
                        Trix::make('Default Description', 'default_description'),
                ])->dependsOn('description_type', 0),

This works.

2. If I add BelongsTo::make('Country', 'country'), Inside the NovaDependencyContainer This Does Not Work:

                NovaDependencyContainer::make([
                        Trix::make('Default Description', 'default_description'),
                        BelongsTo::make('Country', 'country'),
                ])->dependsOn('description_type', 0),

The Country list in empty.

If I move BelongsTo::make('Country', 'country'), outside of the NovaDependencyContainer the Country list is populated.

Is there a way to get option 2 to work?

@MarcosGit
Copy link

Hi, daugaard47

You can change the BelongsTo to normal select and make your query:

Select::make('Type')->options(function () {
return array_filter(Element::pluck('name', 'id')->toArray());
}),

@alex-osborn
Copy link

Still occurring.

Another workaround if anyone runs into this. You can get the relationship loading if you tell Nova about it, by registering a top-level field. You can then set it to always be hidden.

// Problem: The BelongsTo won't load in the NovaDepdenencyContainer
// Solution: Add a BelongsTo and force-hide it.
BelongsTo::make('Template', 'template', ChecklistGroupResource::class)
    ->onlyOnDetail()
    ->hideFromDetail(),
NovaDependencyContainer::make([
    BelongsTo::make('Template', 'template', ChecklistGroupResource::class)
])
     ->dependsOn('type', ChecklistGroupType::COMPANY_FROM_TEMPLATE),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants