PHP code example of sbine / simple-tenancy

1. Go to this page and download the library: Download sbine/simple-tenancy 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/ */

    

sbine / simple-tenancy example snippets


class Account extends Model
{
    use \Sbine\Tenancy\HasTenancy;
}

class MyTenant extends \Sbine\Tenancy\Tenant
{
    /**
     * Retrieve the column identifying each model's tenant.
     */
    public function column()
    {
        return 'tenant_hashid';
    }

    /**
     * Retrieve the current tenant's identifier.
     */
    public function id()
    {
        return $this->user->hashid;
    }
}

    // In AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(\Sbine\Tenancy\Tenant::class, function () {
            // Throw an AuthenticationException if auth check fails
            return new \Sbine\Tenancy\Tenant(Auth::authenticate());
        });
    }

    // In AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(\Sbine\Tenancy\Tenant::class, function () {
            return new \Sbine\Tenancy\Tenant(Auth::user(), function ($user) {
                return $user->can('admin');
            });
        });
    }

    // In AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(\Sbine\Tenancy\Tenant::class, function () {
            return new MyTenant;
        });
    }

    $this->app->singleton(\Sbine\Tenancy\Tenant::class, \Sbine\Tenancy\SuperAdmin::class);