From a368078dfebe0c087e119c3eb921e3843af2f378 Mon Sep 17 00:00:00 2001 From: Impeck Date: Sat, 9 Apr 2022 05:02:44 +0500 Subject: [PATCH 1/2] add Laravel Orchid integration (#157) --- navigation.php | 3 +- source/docs/v3/integrations/orchid.blade.md | 42 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 source/docs/v3/integrations/orchid.blade.md diff --git a/navigation.php b/navigation.php index 5220d3f..a010f94 100644 --- a/navigation.php +++ b/navigation.php @@ -66,7 +66,7 @@ return [ 'url' => 'usage', 'children' => [ 'Creating Tenants' => 'creating-tenants', - 'Tenant Migrations'=> 'tenant-migrations', + 'Tenant Migrations' => 'tenant-migrations', 'Tenant Routes' => 'tenant-routes', 'Tenant Storage' => 'tenant-storage', 'Tenant Manager' => 'tenant-manager', @@ -205,6 +205,7 @@ return [ 'Nova' => 'integrations/nova', 'Telescope' => 'integrations/telescope', 'Livewire' => 'integrations/livewire', + 'Orchid' => 'integrations/orchid', ], ], 'Console commands' => 'console-commands', diff --git a/source/docs/v3/integrations/orchid.blade.md b/source/docs/v3/integrations/orchid.blade.md new file mode 100644 index 0000000..0637898 --- /dev/null +++ b/source/docs/v3/integrations/orchid.blade.md @@ -0,0 +1,42 @@ +--- +title: Laravel Orchid integration +extends: _layouts.documentation +section: content +--- + +# Laravel Orchid {#laravel-orchid} +The instruction is written for a newly installed Orchid platform, it is proposed to use the platform as a central application and the tenant app. + +## Both in the central app and the tenant app + +Laravel Orchid has already been installed according to the [documentation Orchid](https://orchid.software/en/docs/installation/). All the steps have also been completed [Quickstart Tutorial](/docs/v3/quickstart). + +- To use Orchid both in the central & tenant parts you need to enable [Universal Routes](docs/v3/features/universal-routes). +- Add the tenancy middleware to your `config\platform.php` + ```php + 'middleware' => [ + 'public' => ['web', 'universal', \Stancl\Tenancy\Middleware\InitializeTenancyByDomain::class], + 'private' => ['web', 'platform', 'universal', \Stancl\Tenancy\Middleware\InitializeTenancyByDomain::class], + ], + ``` +- Add a route to `routes\platform.php` + ```php + Route::screen('/', PlatformScreen::class) + ->name('platform.index') + ->breadcrumbs(function (Trail $trail) { + return $trail->push(__('Home'), route('platform.index')); + }); + ``` +- Tenant Routes `routes\tenant.php` + ```php + Route::middleware([ + 'web', + 'platform', + InitializeTenancyByDomain::class, + PreventAccessFromCentralDomains::class, + ])->prefix('admin')->group(function () { + Route::get('/', function () { + return 'This is your multi-tenant application. The id of the current tenant is ' . tenant('id'); + }); + }); + ``` \ No newline at end of file From d0faea78b22cf8e24c62a16ac767e656fa1c2661 Mon Sep 17 00:00:00 2001 From: ianrobertsFF <91917328+ianrobertsFF@users.noreply.github.com> Date: Sat, 9 Apr 2022 19:04:11 +0100 Subject: [PATCH 2/2] Added withoutEvents advisory (#158) Added advisory to let users know that withoutEvents is used when creating resources as a result of a sync. --- source/docs/v3/synced-resources-between-tenants.blade.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/docs/v3/synced-resources-between-tenants.blade.md b/source/docs/v3/synced-resources-between-tenants.blade.md index f028db9..ae0b98b 100644 --- a/source/docs/v3/synced-resources-between-tenants.blade.md +++ b/source/docs/v3/synced-resources-between-tenants.blade.md @@ -26,6 +26,8 @@ You will need two models for the resource. One for the tenant database and one f Both models must use the `ResourceSyncing` trait. This trait makes sure that a `SyncedResourceSaved` event is fired whenever the model is saved. The `UpdateSyncedResource` listener will update the resource in the central database and in all tenant databases where the resource exists. The listener is registered in your `TenancyServiceProvider`. +It is important to note that when a model is updated or created as a result of being synchronised, that model is called with `withoutEvents` and as such if you rely on the saving or creating events you will need to implement this in some other way. + An important requirement of the `Syncable` interface is the `getSyncedAttributeNames()` method. You don't want to sync all columns (or more specifically, attributes, since we're talking about Eloquent models — **accessors & mutators are supported**). In the `users` example, you'd likely only want to sync attributes like the name, email and password, while keeping tenant-specific (or workspace-specific/team-specific, whatever makes sense in your project's terminology) attributes independent. The resource needs to have the same global ID in the central database and in tenant databases.