tenancy-docs/source/docs/v3/integrations/scout.blade.md

922 B

title extends section
Laravel Scout integration _layouts.documentation content

Laravel Scout

Note: Make sure the Scout config file is published

After installing Scout, make sure the models of all tenants aren't being imported in the same index by prefixing the model indices with the current tenant's key. You can achieve that by adding a listener with this code to the TenancyInitialized event in your TenancyServiceProvider:

config(['scout.prefix' => tenant()->getTenantKey()]);

And to reset the prefix as tenancy ends, add a listener with this code to the TenancyEnded event:

config(['scout.prefix' => '']);

After that, you can import your existing records for each tenant using the tenants:run command:

php artisan tenants:run scout:import --argument="model=App\Models\YourSearchableModel"