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

Colin_Laws's avatar

Query collection with Laravel Scout and Algolia

Is it possible to search a collection returned by a pivot relationship with the search('...') function?

    // Arbitrary account model instance
    $account = App\Models\Account::first(); 

    // Pulling the pivot relationship and attempting to query
    // a collection of models with the search function
    $account->invites()->search('...')->paginate()

I know at this point I'm really just filtering a set of data, but I didn't know if I could use the convenience of a single search() function to handle my search logic instead of customizing it every time I want to create a search method.

Also, I have implemented a query repository, so technically I could put search logic in there and call it where I need it, but I like being able to just say search();

0 likes
0 replies

Please or to participate in this conversation.