Skip to content

BelongsTo doesn't filter BelongsTo in dependsOn() #5356

@LorenzoSapora

Description

@LorenzoSapora
  • Laravel Version: 9.x
  • Nova Version: 4.21.x
  • PHP Version: 8.1

When using A BelongsTo field, the second field doesn't appear to be filtering by the original.

Normally I'd just replace the second BelongsTo (product) with a select, with ->options(Product::where('client_id', $formData->client_id)), but then I'd lose out on the inline creation modal, as well as all the benefits of BelongsTo.

Am I missing something from the below?

    public function fields(NovaRequest $request): Array
    {
        return [
            BelongsTo::make('Client', 'client', 'App\Nova\Client')
                ->showCreateRelationButton()
                ->modalSize('FULL')
                ->nullable()
                ->withoutTrashed()
                ->searchable(),

            BelongsTo::make('Product', 'product', 'App\Nova\Product')
                ->hide()
                ->dependsOn(
                    ['client'],
                    function (BelongsTo $field, NovaRequest $request, FormData $formData) {
                        if ($formData->client) {
                            $field
                                ->show()
                                ->showCreateRelationButton()
                                ->modalSize('full')
                                ->nullable()
                                ->withoutTrashed()
                                ->searchable();
                        }
                    }
                ),
        ];
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions