44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Config;
|
|
|
|
use CodeIgniter\Events\Events;
|
|
use CodeIgniter\Exceptions\FrameworkException;
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
|
|
/*
|
|
* --------------------------------------------------------------------
|
|
* Application Events
|
|
* --------------------------------------------------------------------
|
|
*/
|
|
|
|
Events::on('pre_system', static function () {
|
|
// Boot Eloquent ORM
|
|
bootEloquent();
|
|
});
|
|
|
|
/**
|
|
* Bootstrap Eloquent ORM with database configuration from environment
|
|
*/
|
|
function bootEloquent(): void
|
|
{
|
|
$capsule = new Capsule();
|
|
|
|
$capsule->addConnection([
|
|
'driver' => 'mysql',
|
|
'host' => $_ENV['DB_HOST'] ?? '127.0.0.1',
|
|
'database' => $_ENV['DB_NAME'] ?? '',
|
|
'username' => $_ENV['DB_USER'] ?? '',
|
|
'password' => $_ENV['DB_PASS'] ?? '',
|
|
'charset' => 'utf8mb4',
|
|
'collation' => 'utf8mb4_unicode_ci',
|
|
'prefix' => '',
|
|
]);
|
|
|
|
// Make this Capsule instance available globally via static methods
|
|
$capsule->setAsGlobal();
|
|
|
|
// Setup the Eloquent ORM
|
|
$capsule->bootEloquent();
|
|
}
|