How to use Config file in Laravel

All of the configuration files for the Laravel framework are stored in the config directory. There are a lot of configuration files by default such as database, mail, queue and so on. We can create our own config file that can be used to set options in our application.

Create Config file

To create a configuration file, we just need to create a file inside config folder and return an array with key-value pair.

    // OR
    'demo' = env('DEMO', true)

We can also use multi-dimensional array to set the value.

        'url' => '',
        'username' => 'kodementor'
    'twitter' => [
        'url' => '',
        'username' => 'kodementor'

Note that the second example pick up the value from .env file. If this is not set, it will take default value true. So, we just need to set option as below in .env file.

// .env
DEMO = false

Get Config value

We can get the cofiguration values using the Config facade. For example:

echo Config::get('mode.test');
// OR
echo Config::get('social.facebook.url');

There is also another method to get config value. We can use config function. For example:

echo config('mode.test');
// OR
echo cofig('social.facebook.url');

Be sure to clear the cached config because config files are cached for faster performance. To know more, here is a nice article explaining all the methods about clearing cache in laravel.

That’s it. Isn’t it pretty easy to set and retrieve cofiguration file in laravel? Drop your thoughts below.

Read More Articles


  1. Hey fantastic blog! Does running a blog similar to this require a large amount
    of work? I have no knowledge of computer programming but I was hoping
    to start my own blog soon. Anyways, if you have
    any ideas or techniques for new blog owners please share.
    I understand this is off subject however I just wanted to ask.
    Thanks a lot! ps4 ps4


Please enter your comment!
Please enter your name here