From 48ee8b4156a75b6c8ea1729dd525887883d3cac7 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Wed, 15 Apr 2026 08:22:39 +0530 Subject: [PATCH] Fix: Load database credentials in constructor to avoid constant expression errors --- app/Config/Database.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/Config/Database.php b/app/Config/Database.php index 928adf5..7332903 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -26,14 +26,14 @@ class Database extends Config */ public array $default = [ 'DSN' => '', - 'hostname' => env('database.default.hostname', 'localhost'), - 'username' => env('database.default.username', 'root'), - 'password' => env('database.default.password', ''), - 'database' => env('database.default.database', 'hms_ci4_2026'), - 'DBDriver' => env('database.default.DBDriver', 'MySQLi'), + 'hostname' => 'localhost', + 'username' => 'root', + 'password' => '', + 'database' => 'hms_ci4_2026', + 'DBDriver' => 'MySQLi', 'DBPrefix' => '', 'pConnect' => false, - 'DBDebug' => env('database.default.DBDebug', true), + 'DBDebug' => true, 'charset' => 'utf8mb4', 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', @@ -41,7 +41,7 @@ class Database extends Config 'compress' => false, 'strictOn' => false, 'failover' => [], - 'port' => env('database.default.port', 3306), + 'port' => 3306, 'numberNative' => false, 'foundRows' => false, 'dateFormat' => [ @@ -194,6 +194,15 @@ class Database extends Config { parent::__construct(); + // Load database credentials from .env + $this->default['hostname'] = env('database.default.hostname', 'localhost'); + $this->default['username'] = env('database.default.username', 'root'); + $this->default['password'] = env('database.default.password', ''); + $this->default['database'] = env('database.default.database', 'hms_ci4_2026'); + $this->default['DBDriver'] = env('database.default.DBDriver', 'MySQLi'); + $this->default['DBDebug'] = env('database.default.DBDebug', true); + $this->default['port'] = env('database.default.port', 3306); + // Ensure that we always set the database group to 'tests' if // we are currently running an automated test suite, so that // we don't overwrite live data on accident.