Global Config values In Laravel

Today I want to create a page for sending contact us mail in site,

For that I have to define admin mail id and admin name as a config value and i want to access the same in same in many  places,

I had googled for some time , to find out how can i define my constant in laravel and one of my friend (Ranjith) help to do that ,

Here i am writing how we can use a  Config values   in laravel,

1. If we want to define all our constants in a custom page ,

We can create a page (Here i am calling constants.php )
and inside that we can define like key value pair

return array(
 'custome_name' =>'custome_value',

And we call the values as below

$cvalue = Config::get('filename.custome_name');

Here we will get our custom_value in $cvalue

Let us look an example


return array(

    'admin_email' =>'',
    'admin_name' =>'Admin',


Now let us see How we can retrieve the config in your code somewhere

echo  Config::get('constants.admin_email');
echo  Config::get('constants.admin_name')

Hope it will help some one 🙂

Thank you Ranjith

I made small changes,

thank you Martin Tonev for correcting from variable to config

 21,978 total views,  2 views today


  1. it’s helpful,3Q.

  2. Thanks it works!

  3. This was really helpful. Thank You. For sensitive information don’t forget to;
    * add the (constants.php) file into ‘.gitignore’ as well as
    * making sure the web server is the owner of the file.

Leave a Reply

Your email address will not be published.