PHP code example of aventure-cloud / laravel-tenancy

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

    

aventure-cloud / laravel-tenancy example snippets



    'tenant' => [
        // The model representing a tenant
        'model' => App\Tenant::class,

        // The foreign key for identifying tenant ownership in all eloqunet models
        'foreign_key' => env('MULTITENANCY_FOREIGN_KEY', 'company_id'),
        
        // The field of tenant model used as subdomain key
        'identifier' => 'slug',
    ],

    // Field used to identify a tenant in the url
    'hostname' => [
        'default' => env('MULTITENANCY_HOSTNAME_DEFAULT', 'www.mydomain.com')
    ]


class Post extends Model 
{
    use BelongsToTenant;
    
    // ...
}

class Company extends Model 
{
    use IsTenant;
    
    // ...
}

protected function mapTenantRoutes()
{
    // Wrap tenant routes here before every others middleware
    Tenancy::routes()->group(function () {
    
        Route::middleware('web')
            ->namespace($this->namespace)
            ->group(base_path('routes/tenant/web.php'));
            
    });
}

protected function map()
{

    Route::domain(config('multitenancy.hostname.default')->group(function() {
		$this->mapApiRoutes();
        $this->mapWebRoutes();
    });
	
}

public function store(Request $request)
{
    $request->validate([
        'email' => [Tenancy::unique('users', 'email')],
        'role_id' => [Tenancy::exists('roles', 'id')]
    ])
}

class ProcessPodcast implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, TenantAwareJob;
    
    // ...
}