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

packy's avatar
Level 7

Change how resousrce and global search work

Right now my app only has 2 resources I want searched. Both resources will need to search an email column that is encrypted. I currently use something like this to find the records since they are encrypted:

Consumer::all()->filter(function ($record) use ($email) {
            if ($record->email == $email) {
                return $record;
            }
        });

How can I adjust the how "search" is done? Its a must for the app per the client, but so is encrypting PII. I should be able to use that same chunk of code if I knew where to overwrite how to search

0 likes
3 replies
bobbybouwmann's avatar

You can override the static indexQuery in your resource to adjust the search

public static function indexQuery
{
    if (!request()->filled('filters')) {
        return $query->whereNull('downloaded_at');
    }

    return $query;
}
packy's avatar
Level 7

Is there any docs on this? I guess I dont understand what ->filled('filters') is and $query->whereNull('downloaded_at'); or is that just and example?

packy's avatar
Level 7

Okay, so if I do this:

public static function indexQuery(NovaRequest $request, $query)
    {
        if (request()->filled('search')) {
            $term = $request->search;

            $matches = AppConsumer::all()->filter(function ($record) use ($term) {
                if ($record->email == $term) {
                    return $record;
                }
            });

            return $matches;
        }

        return $query;
    }

it returns noting. But if I dd($matches); before the return it shows what I need. What am I missing?

Please or to participate in this conversation.