Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nabeelgillani's avatar

Filter Nova Relationship field based on another relationship in the same resource

Hi All,

Help needed!

I need to figure out a way to filter the BelongsTo Relationship field on my Resource called "Due", this is supposed to record the dues that students owe. Here is the scenario... Students Enrol in a Course(s) and Each course has Fee(s) Once Enrolled Student need to be assigned these Fee(s) as Due(s) with Due Date so payments can be tracked.

I am having trouble filtering the Fee(s) on the Due resource so that Fee(s) for only the related Enrolled Course are loaded.

I have following models

Student (id, name) Course (id, name) course_student (id, course_id, student_id) (know as Enrolment resource in Nova) Fee (id, course_id, amount) Due (id, course_student_id, fee_id, due_at)

Relationships

  • Student and courses have Many-to-Many relationship via course_student
  • Fee belongsTo a Course and Course hasMany Dues
  • Due belongsTo course_student also

So basically the issue is with the last step on the Due Resource where I want to display fees only for the enrolled -> course.

BelongsTo::make('Enrolment', 'course_student')->searchable(),

            //display fees only for the course that has been Enrolled
            BelongsTo::make('Fee')->sortable(),

            
            Number::make('Units')->sortable(),

            Date::make('Due At')->sortable(),

            Text::make('Comments'),

            HasMany::make('Payments')

I am fimilar with relateableQuery(NovaRequest $request, $query){ // } or relateableFees(NovaRequest $request, $query){ // }

Thanks and Regards

0 likes
0 replies

Please or to participate in this conversation.