You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This event will fire when a tenant is being made the current one. At this point none of [the tasks](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/overview/) have been executed.
10
+
This event will fire when a tenant is being made the current one. At this point none of [the tasks](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/overview/) have been executed.
11
11
12
12
It has one public property `$tenant`, that contains an instance of `Spatie\Multitenancy\Models\Tenant`.
This event will fire when a tenant has been made the current one. At this point the `makeCurrent` method of all of [the tasks](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/overview/) have been executed. The current tenant also have been bound as `currentTenant` in the container.
16
+
This event will fire when a tenant has been made the current one. At this point the `makeCurrent` method of all of [the tasks](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/overview/) have been executed. The current tenant also have been bound as `currentTenant` in the container.
17
17
18
18
It has one public property `$tenant`, that contains an instance of `Spatie\Multitenancy\Models\Tenant`.
This event will fire when a tenant is being forgotten. At this point none of [the tasks](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/overview/) have been executed.
22
+
This event will fire when a tenant is being forgotten. At this point none of [the tasks](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/overview/) have been executed.
23
23
24
24
It has one public property `$tenant`, that contains an instance of `Spatie\Multitenancy\Models\Tenant`.
This event will fire when a tenant has been forgotten. At this point the `forgotCurrent` method of all of [the tasks](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/overview/) have been executed. `currentTenant` in the container has been emptied.
28
+
This event will fire when a tenant has been forgotten. At this point the `forgotCurrent` method of all of [the tasks](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/overview/) have been executed. `currentTenant` in the container has been emptied.
If you cannot change an Artisan command yourself, for instance a command from Laravel itself or a command from a package, you can use `tenants:artisan <artisan command>`. This command will loop over tenants and for each of them make that tenant current, and execute the artisan command.
44
44
45
-
When your tenants each have their own database, you could migrate each tenant database with this command (given you are using a task like [`SwitchTenantDatabase`](https://docs.spatie.be/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/switching-databases)):
45
+
When your tenants each have their own database, you could migrate each tenant database with this command (given you are using a task like [`SwitchTenantDatabase`](https://docs.spatie.be/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/switching-databases)):
If there is a tenant returned by the tenant finder, [all configured tasks](https://docs.spatie.be/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/overview/) will be performed on it. After that, the tenant instance will be bound in the container using the `currentTenant` key.
22
+
If there is a tenant returned by the tenant finder, [all configured tasks](https://docs.spatie.be/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/overview/) will be performed on it. After that, the tenant instance will be bound in the container using the `currentTenant` key.
23
23
24
24
```php
25
25
app('currentTenant') // will return the current tenant or `null`
Copy file name to clipboardexpand all lines: docs/basic-usage/working-with-the-current-tenant.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ You can manually make a tenant the current one by calling `makeCurrent()` on it.
43
43
$tenant->makeCurrent();
44
44
```
45
45
46
-
When a tenant is made the current one, the package will run the `makeCurrent` method of [all tasks configured](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/overview/) in the `switch_tenant_tasks` key of the `multitenancy` config file.
46
+
When a tenant is made the current one, the package will run the `makeCurrent` method of [all tasks configured](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/overview/) in the `switch_tenant_tasks` key of the `multitenancy` config file.
This middleware will respond with an unauthorized response code (401) when the user tries to use their session to view another tenant. Make sure to include `\Spatie\Multitenancy\Http\Middleware\NeedsTenant` first, as this will [handle any cases where a valid tenant cannot be found](/docs/laravel-multitenancy/v3/advanced-usage/ensuring-a-current-tenant-has-been-set).
176
+
This middleware will respond with an unauthorized response code (401) when the user tries to use their session to view another tenant. Make sure to include `\Spatie\Multitenancy\Http\Middleware\NeedsTenant` first, as this will [handle any cases where a valid tenant cannot be found](/docs/laravel-multitenancy/v4/advanced-usage/ensuring-a-current-tenant-has-been-set).
177
177
178
178
### Next steps
179
179
180
-
If you prefer to use just one glorious database for all your tenants, read the installation instructions for [using a single database](/docs/laravel-multitenancy/v3/installation/using-a-single-database).
180
+
If you prefer to use just one glorious database for all your tenants, read the installation instructions for [using a single database](/docs/laravel-multitenancy/v4/installation/using-a-single-database).
181
181
182
-
If you want to use separate databases for each tenant, head over to the installation instructions for [using multiple databases](/docs/laravel-multitenancy/v3/installation/using-multiple-databases).
182
+
If you want to use separate databases for each tenant, head over to the installation instructions for [using multiple databases](/docs/laravel-multitenancy/v4/installation/using-multiple-databases).
If you want to determine the "current" tenant some other way, you can [create a custom tenant finder](/docs/laravel-multitenancy/v3/basic-usage/automatically-determining-the-current-tenant/).
22
+
If you want to determine the "current" tenant some other way, you can [create a custom tenant finder](/docs/laravel-multitenancy/v4/basic-usage/automatically-determining-the-current-tenant/).
Copy file name to clipboardexpand all lines: docs/installation/using-a-single-database.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Using a single database
3
3
weight: 2
4
4
---
5
5
6
-
Before using the following instructions, make sure you have performed [the base installation steps](/docs/laravel-multitenancy/v3/installation/base-installation) first.
6
+
Before using the following instructions, make sure you have performed [the base installation steps](/docs/laravel-multitenancy/v4/installation/base-installation) first.
7
7
8
8
Only use the instructions on this page if you want to use one database.
9
9
@@ -22,6 +22,6 @@ This will create the `tenants` table which holds configuration per tenant.
22
22
23
23
### Next steps
24
24
25
-
When using multiple tenants, you probably want to [isolate the cache](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/prefixing-cache/) or use your own separated filesystems per tenant, ... These things are performed by [task classes](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/overview/) that will be executed when making a tenant the current one.
25
+
When using multiple tenants, you probably want to [isolate the cache](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/prefixing-cache/) or use your own separated filesystems per tenant, ... These things are performed by [task classes](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/overview/) that will be executed when making a tenant the current one.
26
26
27
-
The package also has an option to [make the queue tenant aware](/docs/laravel-multitenancy/v3/basic-usage/making-queues-tenant-aware/).
27
+
The package also has an option to [make the queue tenant aware](/docs/laravel-multitenancy/v4/basic-usage/making-queues-tenant-aware/).
Copy file name to clipboardexpand all lines: docs/installation/using-multiple-databases.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Using multiple databases
3
3
weight: 3
4
4
---
5
5
6
-
Before using the following instructions, make sure you have performed [the base installation steps](/docs/laravel-multitenancy/v3/installation/base-installation) first.
6
+
Before using the following instructions, make sure you have performed [the base installation steps](/docs/laravel-multitenancy/v4/installation/base-installation) first.
7
7
8
8
Only use the instructions on this page if you want each of your tenants to have their own database.
9
9
@@ -79,19 +79,19 @@ You should add this task to the `switch_tenant_tasks` key.
79
79
],
80
80
```
81
81
82
-
The package also provides [other tasks](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/overview/) that you could optionally add to `switch_tenant_tasks`. You can also [create a custom task](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/creating-your-own-task/).
82
+
The package also provides [other tasks](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/overview/) that you could optionally add to `switch_tenant_tasks`. You can also [create a custom task](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/creating-your-own-task/).
83
83
84
84
### Creating tenant databases
85
85
86
-
Now that automatic database switching for tenants is configured, you can migrate the tenant databases. Because there are so many ways to go about it, the package does not handle creating databases. You should take care of creating new tenant databases in your own application code. A nice place to trigger this could be [when a `Tenant` model gets created](/docs/laravel-multitenancy/v3/advanced-usage/using-a-custom-tenant-model/#performing-actions-when-a-tenant-gets-created).
86
+
Now that automatic database switching for tenants is configured, you can migrate the tenant databases. Because there are so many ways to go about it, the package does not handle creating databases. You should take care of creating new tenant databases in your own application code. A nice place to trigger this could be [when a `Tenant` model gets created](/docs/laravel-multitenancy/v4/advanced-usage/using-a-custom-tenant-model/#performing-actions-when-a-tenant-gets-created).
87
87
88
88
If you want to get a feel of how the package works, you could create a couple of rows in the `tenants` table, fill the `database` attribute and manually create those databases.
89
89
90
90
### Migrating tenant databases
91
91
92
92
When you want to migrate tenant databases, all future migrations should be stored in `database/migrations`.
93
93
94
-
To perform these migrations, you can use [the `tenants:migrate` command](/docs/laravel-multitenancy/v3/advanced-usage/executing-artisan-commands-for-each-tenant). This command will loop over all rows in the `tenants` table. It will make each tenant the current one, and migrate the database.
94
+
To perform these migrations, you can use [the `tenants:migrate` command](/docs/laravel-multitenancy/v4/advanced-usage/executing-artisan-commands-for-each-tenant). This command will loop over all rows in the `tenants` table. It will make each tenant the current one, and migrate the database.
@@ -144,4 +144,4 @@ All models in your project should either use the `UsesLandlordConnection` or `Us
144
144
145
145
### Next steps
146
146
147
-
When using multiple tenants, you probably want to [isolate the cache](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/prefixing-cache/). This is performed by task classes that will be executed when making a tenant the current one.
147
+
When using multiple tenants, you probably want to [isolate the cache](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/prefixing-cache/). This is performed by task classes that will be executed when making a tenant the current one.
Copy file name to clipboardexpand all lines: docs/using-tasks-to-prepare-the-environment/overview.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,11 @@ When making a tenant the current one, the tasks inside the `switch_tenant_tasks`
7
7
8
8
The philosophy of this package is that it should only provide the bare essentials to enable multitenancy. That's why it only provides two tasks out of the box. These tasks serve as example implementations.
9
9
10
-
You can easily [create your own tasks](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/creating-your-own-task/) that fit your particular project.
10
+
You can easily [create your own tasks](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/creating-your-own-task/) that fit your particular project.
11
11
12
12
The package ships with these tasks:
13
13
14
-
-[switch the tenant database](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/switching-databases) (required when using multiple tenant databases)
15
-
-[prefixing the cache](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/prefixing-cache)
14
+
-[switch the tenant database](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/switching-databases) (required when using multiple tenant databases)
15
+
-[prefixing the cache](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/prefixing-cache)
16
16
17
17
These tasks are optional. When you need one, just add it to the `switch_tenant_tasks` key of the `multitenancy` config file.
Behind the scenes, this works by dynamically changing the `cache.prefix` in the `cache` config file whenever another tenant is made current.
43
43
44
-
If you want to make the cache tenant aware in another way, you should [create your own task](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/creating-your-own-task/). You can take a look at the source code of `PrefixCacheTask` for inspiration.
44
+
If you want to make the cache tenant aware in another way, you should [create your own task](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/creating-your-own-task/). You can take a look at the source code of `PrefixCacheTask` for inspiration.
Copy file name to clipboardexpand all lines: docs/using-tasks-to-prepare-the-environment/switching-databases.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -16,4 +16,4 @@ To use this task, you should add it to the `switch_tenant_tasks` key in the `mul
16
16
],
17
17
```
18
18
19
-
If you want to change other database connection properties beside the database name, you should [create your own task](/docs/laravel-multitenancy/v3/using-tasks-to-prepare-the-environment/creating-your-own-task/). You can take a look at the source code of `SwitchTenantDatabaseTask` for inspiration.
19
+
If you want to change other database connection properties beside the database name, you should [create your own task](/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/creating-your-own-task/). You can take a look at the source code of `SwitchTenantDatabaseTask` for inspiration.
0 commit comments