Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
masterix21 committed Jul 18, 2024
1 parent 0863889 commit 5a21693
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
23 changes: 23 additions & 0 deletions docs/advanced-usage/using-a-custom-tenant-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,26 @@ class CustomTenantModel extends Tenant
}
}
```

## How to create a tenant by any model

You can't extend our `Tenant` model in many cases. An example could be when you like to use our package with Team features offered by Laravel Jetstream, so your Team model is also your Tenant.

To accomplish that, you can implement the contract `IsTenant` with our ready-to-use trait `ImplementsTenant`. Take a look at this example:

```php
namespace App\Models;

use Laravel\Jetstream\Team as JetstreamTeam;
use Spatie\Multitenancy\Contracts\IsTenant;
use Spatie\Multitenancy\Models\Concerns\ImplementsTenant;

class Team extends JetstreamTeam implements IsTenant
{
use HasFactory;
use UsesLandlordConnection;
use ImplementsTenant;
}
```

That's all.
11 changes: 4 additions & 7 deletions docs/basic-usage/automatically-determining-the-current-tenant.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ app('currentTenant') // will return the current tenant or `null`
You can create a tenant finder of your own. A valid tenant finder is any class that extends `Spatie\Multitenancy\TenantFinder\TenantFinder`. You must implement this abstract method:

```php
abstract public function findForRequest(Request $request): ?Tenant;
abstract public function findForRequest(Request $request): ?IsTenant;
```

Here's how the default `DomainTenantFinder` is implemented. The `getTenantModel` returns an instance of the class specified in the `tenant_model` key of the `multitenancy` config file.
Expand All @@ -37,18 +37,15 @@ Here's how the default `DomainTenantFinder` is implemented. The `getTenantModel`
namespace Spatie\Multitenancy\TenantFinder;

use Illuminate\Http\Request;
use Spatie\Multitenancy\Models\Concerns\UsesTenantModel;
use Spatie\Multitenancy\Models\Tenant;
use Spatie\Multitenancy\Contracts\IsTenant;

class DomainTenantFinder extends TenantFinder
{
use UsesTenantModel;

public function findForRequest(Request $request):?Tenant
public function findForRequest(Request $request): ?IsTenant
{
$host = $request->getHost();

return $this->getTenantModel()::whereDomain($host)->first();
return app(IsTenant::class)::whereDomain($host)->first();
}
}
```
5 changes: 3 additions & 2 deletions docs/installation/base-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 1
This package can be installed via composer:

```bash
composer require "spatie/laravel-multitenancy:^3.0"
composer require "spatie/laravel-multitenancy:^4.0"
```

### Publishing the config file
Expand Down Expand Up @@ -64,7 +64,8 @@ return [
/*
* This class is the model used for storing configuration on tenants.
*
* It must be or extend `Spatie\Multitenancy\Models\Tenant::class`
* It must extend `Spatie\Multitenancy\Models\Tenant::class` or
* implement `Spatie\Multitenancy\Contracts\IsTenant::class` interface
*/
'tenant_model' => Tenant::class,

Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ title: Requirements
weight: 3
---

This package requires **PHP 8.0+** and **Laravel 8.0+**.
This package requires **PHP 8.2+** and **Laravel 11.0+**.

0 comments on commit 5a21693

Please sign in to comment.