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

djindagi's avatar

Laravel Scout - Typesense - Scoped keys

Hello,

I'm migrating from Algolia to Typesense for my search and I've relied so far on "scoped keys" to always pre-filter results for each user based on their access rights. This was done easily with Algolia.

On Typesense, the same feature exists: https://typesense.org/docs/28.0/api/api-keys.html#generate-scoped-search-key but I cannot find its implementation in the official Scout Driver.

Has anybody any clue how I could implement such mechanism to use, on a user-basis, a scoped key for each of its searches ?

Cheers

0 likes
1 reply
elvisblanco1993's avatar

I may be late to this, but I was running into the same question and currently I'm doing it like so:

// tenant_id is my scoped key in this case.
Contact::search($this->query)
    ->options([
        'filter_by' => 'tenant_id:=' . Auth::user()->current_tenant_id,
    ])->paginate(15);

Make sure to add your scoped keys to both the model's toSearchableArray() method, and configure them as filterable in your scout.php driver settings.

Please or to participate in this conversation.