mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 18:24:03 +00:00
Merge branch 'master' into copy-snippets
This commit is contained in:
commit
9bcf2b89ce
5 changed files with 70 additions and 0 deletions
|
|
@ -209,6 +209,7 @@ return [
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'Console commands' => 'console-commands',
|
'Console commands' => 'console-commands',
|
||||||
|
'Tenant attribute encryption' => 'tenant-attribute-encryption',
|
||||||
'Cached lookup' => 'cached-lookup',
|
'Cached lookup' => 'cached-lookup',
|
||||||
'Real-time facades' => 'realtime-facades',
|
'Real-time facades' => 'realtime-facades',
|
||||||
'Tenant maintenance mode' => 'tenant-maintenance-mode',
|
'Tenant maintenance mode' => 'tenant-maintenance-mode',
|
||||||
|
|
|
||||||
1
package-lock.json
generated
1
package-lock.json
generated
|
|
@ -24968,6 +24968,7 @@
|
||||||
},
|
},
|
||||||
"laravel-mix-jigsaw": {
|
"laravel-mix-jigsaw": {
|
||||||
"version": "git+ssh://git@github.com/iskrisis/laravel-mix-jigsaw.git#7c81913bc5cb6f3c8ab238c97443f059182bce7f",
|
"version": "git+ssh://git@github.com/iskrisis/laravel-mix-jigsaw.git#7c81913bc5cb6f3c8ab238c97443f059182bce7f",
|
||||||
|
"integrity": "sha512-sC8G4X8zfRMXNuZGUhxRIkkIA/EXyIkXNk3V1aVasT1paoV6rLwUXqLSaRW/3Q08ZYQFtJTJrRfssywe8s8Zvw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"from": "laravel-mix-jigsaw@github:iskrisis/laravel-mix-jigsaw",
|
"from": "laravel-mix-jigsaw@github:iskrisis/laravel-mix-jigsaw",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ The list of domains that host your [central app]({{ $page->link('the-two-applica
|
||||||
This config array lets you enable, disable or add your own [tenancy bootstrappers]({{ $page->link('tenancy-bootstrappers') }}).
|
This config array lets you enable, disable or add your own [tenancy bootstrappers]({{ $page->link('tenancy-bootstrappers') }}).
|
||||||
|
|
||||||
### Database {#database}
|
### Database {#database}
|
||||||
|
> Note: If you're using [Laravel Sail](https://laravel.com/docs/9.x/sail), ensure that `DB_USERNAME` has the necessary permissions to create databases. You can grant access to users by running `grant create on *.* to 'sail'@'%';` in the MySQL console.
|
||||||
|
|
||||||
`tenancy.database.*`
|
`tenancy.database.*`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,8 @@ To have users in tenant databases, let's move the `users` table migration (the f
|
||||||
|
|
||||||
## Creating tenants {#creating-tenants}
|
## Creating tenants {#creating-tenants}
|
||||||
|
|
||||||
|
> Note: If you're using [Laravel Sail](https://laravel.com/docs/9.x/sail), ensure that `DB_USERNAME` has the necessary permissions to create databases. You can grant access to users by running `grant create on *.* to 'sail'@'%';` in the MySQL console.
|
||||||
|
|
||||||
For testing purposes, we'll create a tenant in `tinker` — no need to waste time creating controllers and views for now.
|
For testing purposes, we'll create a tenant in `tinker` — no need to waste time creating controllers and views for now.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
|
|
||||||
65
source/docs/v3/tenant-attribute-encryption.blade.md
Normal file
65
source/docs/v3/tenant-attribute-encryption.blade.md
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
---
|
||||||
|
title: Tenant attribute encryption
|
||||||
|
extends: _layouts.documentation
|
||||||
|
section: content
|
||||||
|
---
|
||||||
|
|
||||||
|
# Tenant attribute encryption {#encrypt}
|
||||||
|
|
||||||
|
To encrypt attributes on the Tenant model, store them in [custom columns]({{ $page->link('tenants/#custom-columns') }}) and cast the attributes to `'encrypted'`, or your custom encryption cast.
|
||||||
|
|
||||||
|
For example, we'll encrypt the tenant's database credentials – `tenancy_db_username` and `tenancy_db_password`. We need to create custom columns for these attributes, because by default, they are stored in the virtual `data` column.
|
||||||
|
|
||||||
|
- Add custom columns to the tenants table (we recommend making the string size at least 512 characters, so the string is capable of containing the encrypted data):
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateTenantsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('tenants', function (Blueprint $table) {
|
||||||
|
$table->string('id')->primary();
|
||||||
|
|
||||||
|
// Your custom columns
|
||||||
|
$table->string('tenancy_db_username', 512);
|
||||||
|
$table->string('tenancy_db_password', 512);
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
$table->json('data')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- Define the custom columns on the Tenant model:
|
||||||
|
|
||||||
|
```php
|
||||||
|
public static function getCustomColumns(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id',
|
||||||
|
'tenancy_db_username',
|
||||||
|
'tenancy_db_password',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- Then define casts for the attributes on the model (using [Laravel's encrypted casts](https://laravel.com/docs/9.x/eloquent-mutators#encrypted-casting), or your custom casts):
|
||||||
|
|
||||||
|
```php
|
||||||
|
protected $casts = [
|
||||||
|
'tenancy_db_username' => 'encrypted',
|
||||||
|
'tenancy_db_password' => 'encrypted',
|
||||||
|
];
|
||||||
|
```
|
||||||
Loading…
Add table
Add a link
Reference in a new issue