From 228aad675106cebb767b6b864c18153c3f91b6c2 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 29 Aug 2022 15:09:27 +0200 Subject: [PATCH 1/4] Add integration guide for Laravel Scout --- navigation.php | 1 + source/docs/v3/integrations/scout.blade.md | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 source/docs/v3/integrations/scout.blade.md diff --git a/navigation.php b/navigation.php index 65c3caf..06d2a97 100644 --- a/navigation.php +++ b/navigation.php @@ -204,6 +204,7 @@ return [ 'Passport' => 'integrations/passport', 'Nova' => 'integrations/nova', 'Telescope' => 'integrations/telescope', + 'Scout' => 'integrations/scout', 'Livewire' => 'integrations/livewire', 'Orchid' => 'integrations/orchid', ], diff --git a/source/docs/v3/integrations/scout.blade.md b/source/docs/v3/integrations/scout.blade.md new file mode 100644 index 0000000..c9f7b48 --- /dev/null +++ b/source/docs/v3/integrations/scout.blade.md @@ -0,0 +1,18 @@ +--- +title: Laravel Scout integration +extends: _layouts.documentation +section: content +--- + +# Laravel Scout {#laravel-scout} +After [installing Scout](https://laravel.com/docs/9.x/scout#installation), 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: + +```php +config(['scout.prefix' => tenant()->getTenantKey()]); +``` + +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" +``` From 225b22c03ecbf34e6464a972498587952b202656 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 29 Aug 2022 16:47:10 +0200 Subject: [PATCH 2/4] Add note instructing to make sure the Scout config file is published --- source/docs/v3/integrations/scout.blade.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/docs/v3/integrations/scout.blade.md b/source/docs/v3/integrations/scout.blade.md index c9f7b48..45f7c3d 100644 --- a/source/docs/v3/integrations/scout.blade.md +++ b/source/docs/v3/integrations/scout.blade.md @@ -5,7 +5,9 @@ section: content --- # Laravel Scout {#laravel-scout} -After [installing Scout](https://laravel.com/docs/9.x/scout#installation), 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: +> Note: Make sure the Scout config file is published + +After [installing Scout](https://laravel.com/docs/9.x/scout#installation), 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`: ```php config(['scout.prefix' => tenant()->getTenantKey()]); From 1d68074412790d37b7d058663e5b14a64fd59057 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 30 Aug 2022 11:17:35 +0200 Subject: [PATCH 3/4] Add instruction to empty scout.prefix config on TenancyEnded --- source/docs/v3/integrations/scout.blade.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/docs/v3/integrations/scout.blade.md b/source/docs/v3/integrations/scout.blade.md index 45f7c3d..9d82972 100644 --- a/source/docs/v3/integrations/scout.blade.md +++ b/source/docs/v3/integrations/scout.blade.md @@ -13,6 +13,12 @@ After [installing Scout](https://laravel.com/docs/9.x/scout#installation), make config(['scout.prefix' => tenant()->getTenantKey()]); ``` +And to reset the prefix as tenancy ends, add a listener with this code to the `TenancyEnded` event: + +```php +config(['scout.prefix' => '']); +``` + After that, you can import your existing records for each tenant using the `tenants:run` command: ``` From 10851f74696efd98fa72c60ece8dd6ebec2f688e Mon Sep 17 00:00:00 2001 From: lukinovec Date: Thu, 8 Sep 2022 10:14:51 +0200 Subject: [PATCH 4/4] Update Scout integration page --- source/docs/v3/integrations/scout.blade.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/source/docs/v3/integrations/scout.blade.md b/source/docs/v3/integrations/scout.blade.md index 9d82972..de2f99a 100644 --- a/source/docs/v3/integrations/scout.blade.md +++ b/source/docs/v3/integrations/scout.blade.md @@ -7,19 +7,18 @@ section: content # Laravel Scout {#laravel-scout} > Note: Make sure the Scout config file is published -After [installing Scout](https://laravel.com/docs/9.x/scout#installation), 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`: +After [installing Scout](https://laravel.com/docs/9.x/scout#installation), add `ScoutTenancyBootstrapper` to the bootstrappers in your Tenancy config (`config/tenancy.php`): ```php -config(['scout.prefix' => tenant()->getTenantKey()]); +'bootstrappers' => [ + ... + Stancl\Tenancy\Bootstrappers\Integrations\ScoutTenancyBootstrapper::class, +], ``` -And to reset the prefix as tenancy ends, add a listener with this code to the `TenancyEnded` event: +This makes 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. -```php -config(['scout.prefix' => '']); -``` - -After that, you can import your existing records for each tenant using the `tenants:run` command: +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"