I need to ask stupid question but my question to access .env variable inside it self not from php :
If i have .env
file for larvel5.4 and i have APP_URL
Like this :
APP_ENV=local
APP_KEY=base64:7qLJMqTxrAPk+tLJscVlmrzf2H16tAfbSoCZuleCkxQ=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
and i have multi config variable use the domain link like this :
#Facebook
FACEBOOK_LOGIN_URL=http://localhost:8000/en/portal/facebook_login
FACEBOOK_CALLBACK_URL=http://localhost:8000/en/portal/facebook_callback
#Twitter
TWITTER_LOGIN_URL=http://localhost:8000/en/portal/twitter_login
TWITTER_CALLBACK_URL=http://localhost:8000/en/portal/twitter_callback
#Google
GOOGLE_LOGIN_URL=http://localhost:8000/en/portal/google_login
GOOGLE_CALLBACK_URL=http://localhost:8000/en/portal/google_callback
is there way to access the APP_URL in the same file like this :
FACEBOOK_LOGIN_URL= APP_URL /en/portal/facebook_login
Please i am new member don't give me minus for this question.
Thank you all
You can set default values for environment variables using a .env file, which Compose automatically looks for in project directory (parent folder of your Compose file).
A simple way to update the . env key value in laravel is to add the below code in the controller function where you want to change . env values. $key = 'VARIABLE_NAME'; $value = 'NEW VALUE'; file_put_contents(app()->environmentFilePath(), str_replace($key .
You can keep things simple, while accessing ENV variables you can easily do the following:
Env file:
APP_URL=http://localhost:8000
FACEBOOK_LOGIN_URL=/en/portal/facebook_login
FACEBOOK_CALLBACK_URL=/en/portal/facebook_callback
in Laravel:
env('APP_URL') . env('FACEBOOK_LOGIN_URL');
And Yes we can do that if needed use following syntax:
.env file:
APP_URL=http://localhost:8000
FACEBOOK_LOGIN_URL=${APP_URL}/en/portal/facebook_login
FACEBOOK_CALLBACK_URL=${APP_URL}/en/portal/facebook_callback
In .env file:
APP_URL=http://localhost:8000
FACEBOOK_LOGIN_URL="${APP_URL}/en/portal/facebook_login"
While other answers are correct about using variables stored in .env
. I think it's going to be neater, if you do the following:
url(env('FACEBOOK_LOGIN_URL'))
or:
url(env('FACEBOOK_CALLBACK_URL'))
url()
uses APP_URL
so you don't need to concatenate your .env
variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With