Video Version of the Lesson
[Only for premium members]
[Only for premium members]
[Only for premium members]
The next package we will check is stancl/tenancy. With this package, you can have single and multi-database tenancy. First, we will take a look at a single database approach.
The starting point is the same CRUD with the Project and Task without any tenancy.
So, first, install the package via composer and then run the tenancy:install
command.
composer require stancl/tenancyphp artisan tenancy:installphp artisan migrate
Next, we must add the TenancyServiceProvider
.
bootstrap/providers.php:
return [ App\Providers\AppServiceProvider::class, App\Providers\TenancyServiceProvider::class, ];
Install command created the Migration for the tenants
table. Now we must make a Model for that table and replace the content of the Model with the code from the quickstart.
php artisan make:model Tenant
app/Models/Tenant.php:
namespace App\Models; use Stancl\Tenancy\Database\Models\Tenant as BaseTenant;use Stancl\Tenancy\Contracts\TenantWithDatabase;use Stancl\Tenancy\Database\Concerns\HasDatabase;use Stancl\Tenancy\Database\Concerns\HasDomains; class Tenant extends BaseTenant implements TenantWithDatabase{ use HasDatabase, HasDomains;}
Next, in the config/tenancy.php
, we need to set that package to use...