Populating SelectFilter with relation.

I have a belongsTo relation between my StudentProfile and my User model. From the StudentProfile resource I'm trying to populate a SelectFilter with available courseClasses. The courseClass has a belongsTo with the User. My selectfilter is setup like this:
SelectFilter::make('classname')
->relationship('user', 'class_id')
->label('Klas'),
SelectFilter::make('classname')
->relationship('user', 'class_id')
->label('Klas'),
This however, populates the select filter with all available class id's from the student resource. This way I have duplicates and also selecting one ID just filters one user. What would be the correct approach?
3 Replies
Patrick Boivin
Patrick Boivin14mo ago
What are you trying to show in the filter exactly? All classes or just the classes for this specific student?
jaap4677
jaap467714mo ago
I would like to select one class in my filter and get all students in it. In my current setup, I have e.g. 10 students in class "a" and 5 students in class "b". My filter is populated with 10 x 'a' and 5 x 'b'. Each filter selection just shows one student as result.
Patrick Boivin
Patrick Boivin14mo ago
I see, makes sense. Can you share a bit more information on how the relationships are setup in your models?
Want results from more Discord servers?
Add your server