在Laravel中加载json文件以进行数据库配置

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.

Like @ceejayoz said: either var_dump() or print_r() the $database variable to inspect it. What I could think of is that the JSON returns an object and you thus need to access its values via

$database->host