PHP code example of henryavila / laravel-nova-multitenancy

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

    

henryavila / laravel-nova-multitenancy example snippets


protected $middlewareGroups = [
    // ...
    
    'web' => [
        // ...
        \HenryAvila\LaravelNovaMultitenancy\Http\Middleware\SetTenantMiddleware::class,
    ],
    
    // ...
    
    'tenant' => [
        \HenryAvila\LaravelNovaMultitenancy\Http\Middleware\NeedsTenant::class,
        \HenryAvila\LaravelNovaMultitenancy\Http\Middleware\EnsureValidTenantSession::class,
    ]
];

 protected $listen = [
        \Laravel\Nova\Events\StartedImpersonating::class  => [
            \HenryAvila\LaravelNovaMultitenancy\Listeners\ClearTenantSessionListener::class,
        ],
        \Laravel\Nova\Events\StoppedImpersonating::class => [
            \HenryAvila\LaravelNovaMultitenancy\Listeners\ClearTenantSessionListener::class,
        ],
];

return [
    // database.php
    'tenant_connection' => env('DB_TENANT_CONNECTION', 'tenant'),

// in a routes file

Route::middleware('tenant')->group(function() {
    // routes
});

protected function redirectTo($request)
{
    return $request->expectsJson() ? null : route('nova.login');
}

Route::get('/', [Controller::class, 'index'])
		->defaults(\HenryAvila\LaravelNovaMultitenancy\LaravelNovaMultitenancy::SKIP_ROUTE, true);
bash
php artisan vendor:publish --provider="HenryAvila\LaravelNovaMultitenancy\LaravelNovaMultitenancyServiceProvider" 
bash
php artisan migrate