Search code examples
phplaravellumen

Overriding configuration files of composer packages in Lumen


I have a Lumen project with external Composer packages installed. As usual with Lumen, they're stored in the vendor directory, each in their respective folder. Some of these packages have configuration files, which I would like to override with custom ones.

I have registered the files in my bootstrap/app.php using $app->configure() right after I register the application itself, so it looks like this:

require_once __DIR__ . '/../vendor/autoload.php';

try {
    (new Dotenv\Dotenv(__DIR__ . '/../'))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
    //
}

$app = new Laravel\Lumen\Application(
    realpath(__DIR__ . '/../')
);

$app->withFacades();
$app->withEloquent();

$app->configure('/Configuration/Lumen/app.php');
$app->configure('/Configuration/Lumen/auth.php');
$app->configure('/Configuration/Tymon/jwt.php');

The files are present in their respective directories, and contain the settings I want Lumen to use instead of the defaults, which are located, respectively, at:

/vendor/laravel/lumen-framework/config/app.php
/vendor/laravel/lumen-framework/config/auth.php
/vendor/tymon/jwt-auth/config/config.php

The problem I run into is that with this configuration, Lumen seems to ignore my custom files, and instead uses the defaults. What am I doing wrong here?


Solution

  • Put your configuration files in config/ and register them in bootstrap/app.php by their filename, without the .php file ending.

    // Your custom config in config/jwt-auth.php
    $app->configure('jwt-auth');