Eloquentのコード
-
PHP Laravel以外でEloquentを使って、複数DBを設定に動的にロードさせる<?php require_once __DIR__ . '/../config/database.php'; $capsule = new \Illuminate\Database\Capsule\Manager; $db_names = array_keys($config['database']); foreach($db_names as $name){ $alis = $name; if($name === reset($db_names)) $alis = 'default'; $capsule->addConnection($config['database'][$name], $alis); } $capsule->setAsGlobal(); $capsule->bootEloquent();
-
PHP Laravel・Eloquent ORMでデータベース設定ファイルを分割して一気にロードする方法<?php $config['database'] = [ 'main' => [ 'driver' => 'sqlite', 'database' => __DIR__ . '/../database/main.sqlite', ], ]; // 個別DB設定を全部require $req_dir = [__DIR__ . '/database/']; foreach ($req_dir as $r) { foreach(glob($r.'*') as $file){ if(is_file($file)){ require_once $file; } } }