Skip to content

Qore Tenant

This module adds Tenant functionality to your application. It can be added to any model of your choosing.

Installation

  1. Install the package via composer:
bash
composer require qore-works-business/qore-tenant
bash
php artisan qore-tenant:install
  1. Add the plugin to the plugins() section of the applications panel service provider:
php
use QoreWorksBusiness\QoreRelation\QoreTenantPlugin;

class QorePanelServiceProvider extends QorePanelServiceProviderBase
{

public function panel(QorePanel|Panel $panel): QorePanel

    return parent::panel($panel)
        // ....
        ->plugins([
            QoreTenantPlugin::make(),
        ]);
}
  1. Add the Tenantable contract and HasTenant trait to your model.
php
use QoreWorksBusiness\QoreTenant\Concerns\HasTenant;
use QoreWorksBusiness\QoreTenant\Contracts\Tenantable;

class Company implements Tenantable
{
    use HasTenant;

    // ...
  1. If you want to use the TenantRelationManager to manage Tenants from QWB, add the TenantRelationManager to your filament resource.
php
use QoreWorksBusiness\QoreTenant\Resources\RelationManagers\TenantRelationManager;

public static function getRelations(): array
{
    return [
        // ...
        TenantRelationManager::class,
    ];
}
  1. If you want to use Tenant information in blade files you can use the TenantComposer view composer in your AppServiceProvider.
php
use QoreWorksBusiness\QoreTenant\View\Composers\TenantComposer;

public function boot(): void
{
    view()->composer([
        // any blade files
        'application.portal.layouts.app',
        'application.portal.layouts.guest',
    ], TenantComposer::class);
}
  1. To route to the correct subdomain you can use the TenantBySubdomainMiddleware middleware. You can use this for most QWB applications (website, portal). Currently Statamic websites are not supported out of the box, but can work with Laravel subdomain routing.
php
//config/portal.php
use QoreWorksBusiness\QoreTenant\Http\Middleware\TenantBySubdomainMiddleware;

return [
    'middleware' => [
        'web',
        TenantBySubdomainMiddleware::class,
    ],
    // ...
];
  1. Add your main domain to the .env
MAIN_DOMAIN=