3.x redesign

This commit is contained in:
Samuel Štancl 2020-06-08 21:20:15 +02:00
parent 857122540f
commit f8f354c323
229 changed files with 201175 additions and 22440 deletions

View file

@ -0,0 +1,20 @@
---
title: Laravel Horizon integration
extends: _layouts.documentation
section: content
---
# Laravel Horizon
Make sure your [queues]({{ $page->link('queues') }}) are configured correctly before using this.
You may add the current tenant's id to your job tags:
```php
public function tags()
{
return [
'tenant' => tenant('id'),
];
}
```

View file

@ -0,0 +1,27 @@
---
title: Livewire integration
extends: _layouts.documentation
section: content
---
# Livewire
Open the `config/livewire.php` file and change this:
```php
'middleware_group' => ['web'],
```
to this:
```php
'middleware_group' => [
'web',
'universal',
InitializeTenancyByDomain::class, // or whatever tenancy middleware you use
],
```
Now you can use Livewire both in the central app and the tenant app.
Also make sure to enable *universal routes*:

View file

@ -0,0 +1,53 @@
---
title: Laravel Nova integration
extends: _layouts.documentation
section: content
---
# Laravel Nova
## In the central app
If you wish to use Laravel Nova in the central application (to manage tenants), you need to make a small change to the Nova migrations, they expect your model primary keys to always be unsigned big integers, but your tenants might be using `string` ids.
You can find the full Nova setup for managing tenants in the [SaaS boilerplate](/saas-boilerplate):
## In the tenant app
To use Nova inside of the tenant part of your application, do the following:
- Publish the Nova migrations and move them to the `database/migrations/tenant` directory.
```
php artisan vendor:publish --tag=nova-migrations
```
- Prevent Nova from adding its migrations to your central migrations by adding `Nova::ignoreMigrations()` to `NovaServiceProvider::boot()` (Don't do this if you want to use Nova **[both in the central & tenant parts]({{ $page->link('features/universal-routes') }})** of the app.)
- Add the tenancy middleware to your `nova.middleware` config. Example:
```php
'middleware' => [
// You can make this simpler by creating a tenancy route group
InitializeTenancyByDomain::class,
PreventAccessFromCentralDomains::class,
'web',
Authenticate::class,
DispatchServingNovaEvent::class,
BootTools::class,
Authorize::class,
],
```
- In your `NovaServiceProvider`'s `routes()` method, replace the following lines:
```php
->withAuthenticationRoutes()
->withPasswordResetRoutes()
```
with these lines:
```php
->withAuthenticationRoutes(['web', 'tenancy'])
->withPasswordResetRoutes(['web', 'tenancy'])
```

View file

@ -0,0 +1,54 @@
---
title: Laravel Passport integration
extends: _layouts.documentation
section: content
---
# Laravel Passport
> If you just want to write an SPA, but don't need an API for some other use (e.g. mobile app), you can avoid a lot of the complexity of writing SPAs by using [Inertia.js](https://inertiajs.com/).
To use Passport inside the tenant part of your application, you may do the following.
- Add this to the `register` method in your `AppServiceProvider`:
```php
Passport::ignoreMigrations();
Passport::routes(null, ['middleware' => [
// You can make this simpler by creating a tenancy route group
InitializeTenancyByDomain::class,
PreventAccessFromCentralDomains::class,
]]);
```
- `php artisan vendor:publish --tag=passport-migrations` & move to `database/migrations/tenant/` directory
## **Shared keys**
If you want to use the same keypair for all tenants, do the following.
- Don't use `passport:install`, use just `passport:keys`. The install command creates keys & two clients. Instead of creating clients centrally, create `Client`s manually in your [tenant database seeder]({{ $page->link('configuration#seeder-params') }}).
## **Tenant-specific keys**
If you want to use a unique keypair for each tenant, do the following. (Note: The security benefit of doing this isn't probably that big, since you're likely already using the same `APP_KEY` for all tenants.)
There are multiple ways you can store & load tenant keys, but the most straightforward way is to store the keys in the on the tenant model and load them into the `passport` configuration using the **[Tenant Config]({{ $page->link('features/tenant-config') }})** feature:
- Uncomment the `TenantConfig` line in your `tenancy.features` config
- Configure the mapping as follows:
```php
[
'passport_public_key' => 'passport.public_key',
'passport_private_key' => 'passport.private_key',
],
```
And again, you need to create clients in your tenant database seeding process.
## Using Passport in both the central & tenant app
![Passport for both central & tenant app](/assets/images/passport_universal.png)
And make sure you enable the *Universal Routes* feature.

View file

@ -0,0 +1,37 @@
---
title: Integration with Spatie packages
extends: _layouts.documentation
section: content
---
# Integration with Spatie packages
## **laravel-activitylog**
### For the tenant app:
- Set the `database_connection` key in `config/activitylog.php` to `null`. This makes activitylog use the default connection.
- Publish the migrations and move them to `database/migrations/tenant`. (And, of course, don't forget to run `artisan tenants:migrate`.)
### For the central app:
- Set the `database_connection` key in `config/activitylog.php` to the name of your central database connection.
## **laravel-permission**
Install the package like usual, but publish the migrations and move them to `migrations/tenant`:
```
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"
mv database/migrations/*_create_permission_tables.php database/migrations/tenant
```
Then add this to your `AppServiceProvider::boot()` method:
```php
Event::listen(TenancyBootstrapped::class, function (Tenancy $tenancy) {
\Spatie\Permission\PermissionRegistrar::$cacheKey = 'spatie.permission.cache.tenant.' . $tenancy->tenant->id;
});
```
The reason for this is that spatie/laravel-permission caches permissions & roles to save DB queries, which means that we need to separate the permission cache by tenant.

View file

@ -0,0 +1,11 @@
---
title: Laravel Telescope integration
extends: _layouts.documentation
section: content
---
# Laravel Telescope
Enable the the *Telescope tags* feature to have all Telescope requests tagged with the current tenant's id.
Note that Telescope (& its migrations) will be part of the central app.