How to get data from Config file in 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 .
Controller :
Write the following code inside your controller or any other file for accessing the config file .
public function getStatus() { $data = config('constants.status'); dd($data); }
Output :
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
Thank you for reading this article 😊
For any query do not hesitate to comment 💬