PHP code example of rndwiga / laravel-multi-db-tenant

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

    

rndwiga / laravel-multi-db-tenant example snippets


php artisan vendor:publish

php artisan tenant:basemodels

php artisan tenant:folders

$this->middleware('auth');
$this->middleware('authTenant'); //This is automatically pushed to laravel's kernel

php artisan vendor:publish

php artisan make:migration create_todo_table --create=todos --path=database/migrations/tenant

    $input = $request->all();
    $email = $input['email'];
    $password = $input['password'];
    $name = $input['name'];
    $companyName = $input['company_name'];

    DB::beginTransaction();

    $user = $this->registerUser($email, $password, $name);
    $tenant = $this->registerTenant($companyName);
    $tenantUser = $this->createTenantUserDetails($user, $tenant);
    $tenantDatabase = $this->createTenantDatabase($tenant);

    DB::commit();
    //now we can migrate the database of the tenant using the tenant database settings

    $this->migrateTenantDatabase($tenantDatabase->hostname, $tenantDatabase->database_name,
                                     $tenantDatabase->user_name, $tenantDatabase->password);