- Laravel Version: 9.17
- Nova Version: 4.9
- PHP Version: 8.1.2
Description:
Unable to load only related records in belongsTo field using dependsOn
Detailed steps to reproduce the issue on a fresh Nova installation:
This is a simple example of my code, I am not sure if I am doing something wrong?
And don't want to change BelongsTo::make('License') to a Select field.
//Nova/Order.php
public function fields(NovaRequest $request)
{
return [
BelongsTo::make('User'),
BelongsTo::make('License')
->dependsOn(
['user'],
function (BelongsTo $field, NovaRequest $request, FormData $formData) {
$field->belongsToId = $formData->user; //<<<< this line
}
),
];
}
//Models/Order.php
public function user()
{
return $this->belongsTo(User::class);
}
public function license()
{
return $this->belongsTo(License::class);
}
//Models/User.php
public function licenses()
{
return $this->hasMany(License::class);
}
//Models/License.php
public function user()
{
return $this->belongsTo(User::class);
}
Description:
Unable to load only related records in belongsTo field using dependsOn
Detailed steps to reproduce the issue on a fresh Nova installation:
This is a simple example of my code, I am not sure if I am doing something wrong?
And don't want to change BelongsTo::make('License') to a Select field.