php - Get env variables names by matching text
404
I have some variables with matching names in .env file as below
MY_SITE_01=http://www.google.com
MY_SITE_02=http://www.facebook.com
MY_SITE_03=http://www.twitter.com
Currently to get the value am using
env('MY_SITE_01')
env('MY_SITE_02')
env('MY_SITE_03')
Is there a way I can do it dynamically or just passing MY_SITE and it gets me all the full names of the variables.
Answer
Solution:
There is a way to solve your problem, you can store comma separated websites url into single env variable like shown below :
When you need to retrieve its value, you can do :
Answer
Solution:
You can make a
my_site.php
file and place it inconfig
folder and in the file you could return the data as:Then in your controller or anywhere else you would like, you could use the config helper to retrieve the values.
Answer
Solution:
Add those environments to
config/app.php
as,And get it by,
This will get value from
.env
file so no more need to manage multiple places.