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
<?php return array( 'admin_email' =>'mail@shabeebk.com', '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
22,540 total views, 1 views today
January 6, 2015 at 12:18 am
You’re better off usin env vars for this.
http://laravel.com/docs/4.2/configuration#protecting-sensitive-configuration < version 4.*. Version 5.* uses this: https://github.com/vlucas/phpdotenv
September 24, 2015 at 6:07 am
it’s helpful,3Q.
March 15, 2016 at 6:08 am
Thanks it works!
April 6, 2017 at 1:59 am
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.
June 12, 2017 at 10:01 am
How to delete global variable after it’s used over.