Using Additional Configuration Files with Laravel & Lumen

If you’ve got a growing Lumen application or perhaps you just want clear separation of configuration - it can be beneficial to add more configuration files to the config/ directory.

These files are pretty simple in nature, if I was creating one to configure settings for users, I could create a file called config/user.php containing:

return [
'prefix' => 'user_',
'table' => 'users',
'permissions' => [
CanPost::class,
CanDelete::class,
CanLogin::class,
],
];

Laravel will load this file when accessed by default but Lumen on the other hand doesn’t. To get access to it via the config() helper, you’ll need to add the following line:

$app->configure(‘user’);

To your bootstrap/app.phpfile which will tell Lumen that there is an additional configuration file to use. After this has been done, you’ll be able to use the config() helper like normal. For example, to get the permissions we configured above:

$permissions = config(‘user.permissions');

You can read more about configuration files on the Laravel website.