Did you solved it?
May 19, 2022
9
Level 2
Nova 4 - dependsOn on a BelongsTo relationship
I'm trying to use the dependsOn method on a BelongsTo field relationship.
The documentation shows a simple implementation using a Text field https://nova.laravel.com/docs/4.0/resources/fields.html#dependent-fields
In the code below, I am trying to load only Licenses that the user owns, based on the User that is selected when creating a new Order resource. User hasMany Licenses relationship exists.
Nova/Order.php
BelongsTo::make('User'),
BelongsTo::make('License')
->dependsOn(['user'], function(BelongsTo $LicenseSelect, NovaRequest $request, FormData $formData) {
// need to set the options for this BelongsTo relationship dropdown to show only Licenses that the selected User owns
}),
Models/User.php
public function licenses()
{
return $this->hasMany(License::class);
}
Models/License.php
public function user()
{
return $this->belongsTo(User::class);
}
Please or to participate in this conversation.