PHP code example of binary-cats / laravel-tenant

1. Go to this page and download the library: Download binary-cats/laravel-tenant library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

binary-cats / laravel-tenant example snippets




namespace App\Models;

use BinaryCats\LaravelTenant\Tenantable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Tenantable;

    /*
    |--------------------------------------------------------------------------
    | Binary Cats | Tenants table
    |--------------------------------------------------------------------------
    |
    | Name of the table to hold the tenants
    */
    'listeners' => [
        \Illuminate\Auth\Events\Authenticated::class => [
            # Will register a tenant within TenantManager based on the tenant of the authenticated user
            \BinaryCats\LaravelTenant\Listeners\SetTenant::class,
        ],
        \Illuminate\Auth\Events\Logout::class => [
            # Will de-register a tenant within TenantManager based on the tenant of the user being loged out
            \BinaryCats\LaravelTenant\Listeners\RemoveTenant::class,
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Binary Cats | Routing rules
    |--------------------------------------------------------------------------
    |
    | Whenever a route is requested, one of the items needed is a subdomain.
    |
    */
   'routing' => [

        # Set `autobind` to true to ensure it is resolved automatically
        'autobind' => true,

        # Set `subdomainKey` to the name of the parameter to bind
        'subdomainKey' => 'tenant',

        # If you need to replace the URL generator with yet another
        # Must be implemeting Illuminate\Contracts\Routing\UrlGenerator
        'generator' => \BinaryCats\LaravelTenant\Routing\UrlGenerator::class,
   ],
bash
php artisan vendor:publish --provider=BinaryCats\\LaravelTenant\\TenantServiceProvider
bash
php artisan vendor:publish --provider=BinaryCats\\LaravelTenant\\TenantServiceProvider --tag=migrations
php artisan vendor:publish --provider=BinaryCats\\LaravelTenant\\TenantServiceProvider --tag=config