How to load custom JSON files into Laravel's config

simplestweb.in
2 min read
fairly easy
I wanted to share my solution to loading custom settings from a JSON file into Laravel's config.
Hi All, this is Adi, again with another Laravel blog post. This time Firstly what's the use case for this, there was a client project, where they had a huge list of configurations in a JSON file and I had to use them in the code. An ideal solution for this could be storing these settings in the database and query them on demand, but I was not able to persuade them to this option, so here's my solution to how I did it.

Loading the Settings file

First, let's see how to load this file when the app initializes.

In the code below I load the settings.json that's in the storage folder in my AppServiceProvider 's boot method. But if you have a lot more logic happening in your service provider you can create a new one just for this purpose.

I check if the file exists, if so, I decode the JSON into a PHP array then add it to the app config. Now you are able to access all the key's…
Adi
Read full article