Unlock the Power of Laravel: Fetching Data from Your Config File

How to get data from Config file in Laravel

Get data from config file - Laravel

In this article we will learn how to get data or variable from config files in laravel . We basically stores global variables for any projects which we need to use throughout our project . You just need to create your own file in config folder and add variable inside that file in the form of array . Now let's see how to get data from that config file .

My Config Data :

For example i have created a file named constants.php inside config folder and added an array inside the constants.php file as you can see in the below image . Now we will try to get that array from the config file .

Get data from config file - Laravel

Controller :

Write the following code inside your controller or any other file for accessing the config file .

public function getStatus()
  $data = config('constants.status');

 Output :

Get data from config file - Laravel

Note :

In case you did not get the output use the following two commands because whenever we changes edit anything inside any config file we need to run these two commands .

php artisan config:cache

php artisan config:clear

Previous Post Next Post

Contact Form