nova-belongsto-depend
nova-belongsto-depend copied to clipboard
Multiple Resources using the Same Model, breaking with NovaBelongsToDepend field
I have encountered some odd stuff happening, i have have two resources both using the same model and extend the sme base Resource class.
Resources:
\App\Nova\ReportTestAppointments \App\Nova\TestAppointments
Model:
public static $model = \App\TestAppointment::class;
Within \App\Nova\TestAppointments i have a fields as below.
NovaBelongsToDepend::make('Instructor', 'instructor', User::class) ->placeholder('Choose an instructor') ->optionsResolve(function ($booking) { return \App\User::instructor()->ofBranch($booking->branch_id)->get(['id', 'name']); }) ->rules(new InstructorRequiredRule) ->nullable() // necessary to accept null value ->dependsOn('Booking') ->readonly(function ($request) { return !$request->user()->can(Permissions::TEST_UPDATE_INSTRUCTOR) && !$request->user()->isSuperAdmin(); }),
NovaBelongsToDepend::make('Booking') ->options(\App\Booking::all()) ->readonly(), `
Now i'm getting the below error when i try and access the \App\Nova\TestAppointments resource.
*Can not find the Field "instructor" in the Model "App\Nova\ReportTestAppointments*
I can only assume something is getting confused here as each resource are unrelated to each other beyond the model.
If anyone has an opportunity to provide insight into the above its much appreciated :)
Probably the formatting is slightly better like that:
NovaBelongsToDepend::make('Instructor', 'instructor', User::class)
->placeholder('Choose an instructor')
->optionsResolve(function ($booking) {
return \App\User::instructor()->ofBranch($booking->branch_id)->get(['id', 'name']);
})
->rules(new InstructorRequiredRule)
->nullable() // necessary to accept null value
->dependsOn('Booking')
->readonly(function ($request) {
return !$request->user()->can(Permissions::TEST_UPDATE_INSTRUCTOR) && !$request->user()->isSuperAdmin();
}),
NovaBelongsToDepend::make('Booking')
->options(\App\Booking::all())
->readonly(),
...
I suppose you need to create the relationship field (belongsTo
or hasMany
) in the model