relatableQuery in Laravel Nova and belongTo relationship
Hi!
I have 3 models: banches {id; name} units {id, banch_id, name} elements {id, banch_id, unit_id, name}
I'm create Resource model for Elements, where i'm use 2 belongTo fields: BelongsTo::make('branch', 'branch', '\App\Nova\Branch')->showCreateRelationButton(), BelongsTo::make('unit') ->hide() ->dependsOn('branch', function (BelongsTo $field, NovaRequest $request, FormData $formData) { if ($formData->branch) { $field->show()->showCreateRelationButton(); } } ),
I'm want to filter unit values by branch_id, and for this i make:
public static function relatableUnits(NovaRequest $request, $query) { return $query->where('branch_id', $request->branch); }
But it don't update values in BelognTo field. If i give some value to query it's work, but it's don't update after change, but if i'm dump $query result, it's seems good.
Help please, how i can do filter for belongTo fields values?
Please or to participate in this conversation.