PHP code example of artflow-studio / tenancy

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

    

artflow-studio / tenancy example snippets


// Tenant-scoped routes
Route::middleware(['auth', 'tenant.web'])->prefix('business')->group(function () {
    Route::get('/dashboard', BusinessDashboard::class);
});

// Central-only admin routes
Route::middleware(['central.web', 'auth'])->prefix('admin')->group(function () {
    Route::get('/tenants', TenantsIndex::class);
});

// Both central and tenant
Route::middleware(['universal.web'])->group(function () {
    Route::get('/login', LoginPage::class)->name('login');
});

'central_domains' => [env('APP_DOMAIN', 'localhost')],

'bootstrappers' => [
    \ArtflowStudio\Tenancy\Bootstrappers\DatabaseBootstrapper::class,  // ArtflowStudio\Tenancy\Bootstrappers\FilesystemBootstrapper::class,
],

'cache' => [
    'resolver_store'          => env('AF_TENANCY_CACHE_STORE', 'database'),
    'resolver_fallback_store' => env('AF_TENANCY_CACHE_FALLBACK_STORE', 'database'),
    'resolver_ttl'            => env('AF_TENANCY_CACHE_TTL', 3600),
],

tenancy()               // Tenancy singleton
tenant()                // Active Tenant model or null
get_current_domain()    // Current hostname
tenant_pwa_asset($path) // URL to tenant PWA asset

$tenant = Tenant::factory()->create();

$tenant->run(function () {
    User::create(['name' => 'Alice', 'email' => '[email protected]', 'password' => bcrypt('x')]);
    expect(User::count())->toBe(1);
});
bash
# Tenant lifecycle
php artisan tenant:create
php artisan tenant:list
php artisan tenant:delete {uuid}
php artisan tenant:health

# Database
php artisan tenant:db migrate
php artisan tenant:db migrate --tenant={uuid}
php artisan tenant:connection-test

# SEO & PWA
php artisan tenant:seo:enable --tenant={uuid}
php artisan tenant:pwa:enable --tenant={uuid}

# Diagnostics
php artisan tenancy:performance
php artisan tenant:tinker {uuid}
bash
php artisan test tests/Feature/Tenancy/