mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 10:14:03 +00:00
Merge branch 'master' of github.com:stancl/tenancy-docs
This commit is contained in:
commit
d4eae62096
2 changed files with 62 additions and 23 deletions
|
|
@ -8,13 +8,20 @@ section: content
|
||||||
|
|
||||||
Make sure your [queues]({{ $page->link('queues') }}) are configured correctly before using this.
|
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:
|
## Tags
|
||||||
|
|
||||||
|
You may add the current tenant's id to your job tags by defining a `tags` method on the class:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
/**
|
||||||
|
* Get the tags that should be assigned to the job.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function tags()
|
public function tags()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'tenant' => tenant('id'),
|
'tenant:' . tenant('id'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
@ -41,38 +41,70 @@ That said, automatic tenancy will still work the same way.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- Add an `id` autoincrement column to `domains` table and retroactively generate the ids
|
- Create migration file with `php artisan make:migration upgrade_tenancy_package`
|
||||||
|
|
||||||
(Note: You may want to make this part of a migration)
|
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use Illuminate\Support\Facades\Schema;
|
<?php
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
$domains = DB::table('domains')->get();
|
class UpgradeTenancyPackage extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('domains', function (Blueprint $table) {
|
||||||
|
$table->dropPrimary();
|
||||||
|
});
|
||||||
|
|
||||||
Schema::table('domains', function (Blueprint $table) {
|
Schema::table('domains', function (Blueprint $table) {
|
||||||
$table->unsignedBigInteger('id')->nullable();
|
$table->increments('id')->first();
|
||||||
});
|
$table->unique('domain');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
|
||||||
$counter = 1;
|
Schema::table('tenants', function (Blueprint $table) {
|
||||||
foreach ($domains as $domain) {
|
$table->json('data')->nullable()->change();
|
||||||
DB::table('domains')
|
$table->timestamps();
|
||||||
->where('domain', $domain->domain)
|
});
|
||||||
->update(['id' => $counter]);
|
|
||||||
$counter += 1;
|
DB::table('domains')->update([
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('domains', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('id');
|
||||||
|
$table->dropUnique(['domain']);
|
||||||
|
$table->dropTimestamps();
|
||||||
|
$table->primary('domain');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('tenants', function (Blueprint $table) {
|
||||||
|
$table->json('data')->nullable(false)->change();
|
||||||
|
$table->dropTimestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Schema::table('domains', function (Blueprint $table) {
|
|
||||||
$table->dropPrimary();
|
|
||||||
});
|
|
||||||
Schema::table('domains', function (Blueprint $table) {
|
|
||||||
$table->primary('id'); // todo: here we want to make it autoincrement, not just primary
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- Replace your Http Kernel with a stock version (copy it from laravel/laravel: [https://github.com/laravel/laravel/blob/master/app/Http/Kernel.php](https://github.com/laravel/laravel/blob/master/app/Http/Kernel.php)) and add back in any changes you made. The package now doesn't necessitate any Kernel changes, so remove all of the 2.x ones.
|
- Replace your Http Kernel with a stock version (copy it from laravel/laravel: [https://github.com/laravel/laravel/blob/master/app/Http/Kernel.php](https://github.com/laravel/laravel/blob/master/app/Http/Kernel.php)) and add back in any changes you made. The package now doesn't necessitate any Kernel changes, so remove all of the 2.x ones.
|
||||||
- Delete config, publish it & the new files using `php artisan tenancy:install`
|
- Delete config, publish it & the new files using `php artisan tenancy:install`. Register the new provider (see instructions on the [Installation]({{ $page->link('installation') }}) page)
|
||||||
- Create Tenant model, as instructed on the [Tenants]({{ $page->link('tenants') }}) page
|
- Create Tenant model, as instructed on the [Tenants]({{ $page->link('tenants') }}) page
|
||||||
- Update routes to use the correct middleware, see the [Routes]({{ $page->link('routes') }}) page
|
- Update routes to use the correct middleware, see the [Routes]({{ $page->link('routes') }}) page
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue