PHP code example of envor / laravel-managed-databases

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

    

envor / laravel-managed-databases example snippets


use Envor\ManagedDatabases\ManagedDatabases;

$managerConnection = 'manager_sqlite';
$name = 'database'

ManagedDatabases::createDatabase($name, $managerConnection);

// database

use Envor\ManagedDatabases\ManagedDatabases;

ManagedDatabases::runOnDatabase(
    $database = 'database', 
    $callback = fn() => Artisan::call('migrate', ['--force' => true]), 
    $managerConnection = 'manager_sqlite'
);

use Envor\ManagedDatabases\ManagedDatabases;

ManagedDatabases::createDatabase('database2', 'sqlite');

ManagedDatabases::useDatabase('database2', 'sqlite');

config('database.default');

// database2

config('database.connections.database2')

// [
//     "driver" => "sqlite",
//     "url" => null,
//     "database" => "/home/forge/mysite.com/storage/app/managed_database2.sqlite",
//     "prefix" => "",
//     "foreign_key_constraints" => true,
// ]