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

uicabpatweyler's avatar

Customize the search query in the TextColumn searchable

I have created a page and on it I have the following code that shows a table with the name of the enrolled student according to the school cycle determined by "request('schoolCycle')".

The query to load the table is this

Enrollment::query()
    ->with(['student','schoolCycle','schoolGroup'])
    ->where('school_cycle_id', request('schoolCycle'))

The table loads with the relationships:

->with(['student','schoolCycle','schoolGroup'])

I want to search using the student's name, but I can't get filament to return the student's name. Enrollments are required to belong to the cycle marked by request('schoolCycle') when searching for the student's name.

Thanks for your help

0 likes
1 reply
LaryAI's avatar
Level 58

To customize the search query in the TextColumn to search for a student's name while ensuring that the enrollments belong to the cycle marked by request('schoolCycle'), you need to adjust the searchable method to include the school_cycle_id condition in the search query.

Here's the updated code:

In this solution, the searchable method for the nameStudent column is modified to include the school_cycle_id condition. This ensures that the search is performed within the context of the specified school cycle. The whereHas method is used to filter enrollments based on the student's name, ensuring that the search term is matched against the given_name field of the related student model.

Please or to participate in this conversation.