PHP code example of rolice / laravel-db-switch

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

    

rolice / laravel-db-switch example snippets


Rolice\LaravelDbSwitch\DbSwitchServiceProvider::class,

/*
 * Package Service Providers...
 */
 Rolice\LaravelDbSwitch\DbSwitchServiceProvider::class,

/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's servipoce providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not 

'DbSwitch' => Rolice\LaravelDbSwitch\Facades\DbSwitch::class,

$app->withFacades(true, [
    Rolice\LaravelDbSwitch\Facades\DbSwitch::class => 'DBSwitch'
]);

/*
|--------------------------------------------------------------------------
| Register Facades
|--------------------------------------------------------------------------
|
| A config section for registering facades through class aliases.
|
*/

class_alias(\Rolice\LaravelDbSwitch\Facades\DbSwitch::class, 'DbSwitch');

// Usage through the facade - DbSwitch
DbSwitch::to('my-cool-db'); // The defaut connection
DbSwitch::connectionTo('my-cool-conenction', 'my-cool-db'); // A specific connection database

// Usage through the Laravel Service Container (IoC)
app('db.switch')->to('my-cool-db'); // The defaut connection
app('db.switch')->connectionTo('my-cool-conenction', 'my-cool-db'); // A specific connection database
sh
php /path/to/composer.phar install