Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Resources using the Same Model, breaking with NovaBelongsToDepend field #79

Open
owen-soak opened this issue Dec 18, 2020 · 2 comments

Comments

@owen-soak
Copy link

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.

@owen-soak
Copy link
Author

If anyone has an opportunity to provide insight into the above its much appreciated :)

@MeerKatDev
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants