Skip to content

Commit

Permalink
Upgrade guide
Browse files Browse the repository at this point in the history
  • Loading branch information
masterix21 committed Jul 18, 2024
1 parent 57b0a8d commit f79dd6b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/requirements.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Requirements
weight: 3
weight: 4
---

This package requires **PHP 8.2+** and **Laravel 11.0+**.
2 changes: 1 addition & 1 deletion docs/support-us.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Support us
weight: 2
weight: 3
---

We invest a lot of resources into creating our [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
Expand Down
39 changes: 39 additions & 0 deletions docs/upgrade-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Upgrade guide
weight: 2
---

In the `4.x` version, we have introduced the contract concept to the Tenant so that any model could implement the interface.

The first step to reach our goal is upgrading our package version.

```sh
composer require spatie/laravel-multitenancy:^4.0
```

### Removed `UsesTenantModel` trait
Remove any reference to our old trait `Spatie\Models\Concerns\UsesTenantModel`, because now the right `Tenant` instance can be resolved using `app(IsTenant::class)`.

### Tenant finder
If you are using the default finder included in the package, no changes are required by your side. However, when you are using a custom finder, you need to change the returned value in `findForRequest` method to `?IsTenant`. Example:

```php
use Illuminate\Http\Request;
use Spatie\Multitenancy\Contracts\IsTenant;

class YourCustomTenantFinder extends TenantFinder
{
public function findForRequest(Request $request): ?IsTenant
{
// ...
}
}
```

### Custom tasks
As has already been pointed out for the finder, the same change is required for any task because our `SwitchTenantTask` interface now is:
```php
public function makeCurrent(IsTenant $tenant): void;
```

So, it requires replacing the method parameter from `Tenant $tenant` to `IsTenant $tenant.`

0 comments on commit f79dd6b

Please sign in to comment.