I am recently working on a laravel project. This project needs a database: The data for its configuration is provided while installing this software and its saved in a sw-config.json located at in the root directory like the composer.json file ...
Now I want the laravel database.php to use the data from this file.
I thought that I could simply let php load the json file via file_get_content()
and set the data directly in app/config/database.php
But don't know why it doesn't work ... I have got troubles loading and decoding the json-file. Code looked like this.
$fokusConfigFile = file_get_contents(__DIR__."/../../content/sw-config.json");
$json = json_decode($fokusConfigFile, true);
$database = $json['database'];
$connection = array(
'mysql' => array(
'driver' => 'mysql',
'host' => $database['host'],
'database' => $database['database'],
'username' => $database['username'],
'password' => $database['password'],
'charset' => 'utf8',
'collation' => $database['coalition'],
'prefix' => $database['prefix'],
)
);
As an error message I receive Undefined index 'host' ... Don't see what could be wrong.