In this episode, we dig into how to read and merge config files in our application. First, we tweak our app service provider to allow merging configs into our custom config property. We walk through setting up a helper method (mergeConfigFromFiles
) that reads all files from our config directory.
Along the way, you'll learn how to:
.
and ..
from a scandir
).merge
method on your config class that combines configs using array_merge_recursive
. This ensures that even if config keys are repeated, everything gets merged together properly.app.php
, all its settings sit under the app
key).Once all that's wired up, we demo how you can now neatly access config values from multiple files using dot notation, like app.name
or database.abc
. This makes your app super modular and easy to scale as you add more config files.