10

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

moheb hawari
  • 311
  • 4
  • 9
  • I think its same like txt file, so there is nothing dynamic, whatever you specify will be static. – Rahul Apr 25 '17 at 11:56
  • Possible duplicate of [Laravel 4: how can I get the environment value?](http://stackoverflow.com/questions/14935846/laravel-4-how-can-i-get-the-environment-value) – Sahil Gulati Apr 25 '17 at 11:57
  • i think that too but when you create composer the composer read it as a code file like no space or missing variable .. because that i am wondering if there way to deal with this file .. thank you for your answer – moheb hawari Apr 25 '17 at 11:59
  • This question is creating a lot bad practices... – Jorge Y. C. Rodriguez Apr 26 '17 at 07:06

4 Answers4

5

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
Yogesh Koli
  • 95
  • 1
  • 7
  • You can use environment variables inside .env files by using the ${ENVIRONMENT_VARIABLE} syntax. OP saying 'There is no way' is incorrect. – Verron Knowles Jul 06 '21 at 20:46
1

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.

Ivanka Todorova
  • 9,964
  • 16
  • 66
  • 103
1

In .env file:

APP_URL=http://localhost:8000
FACEBOOK_LOGIN_URL="${APP_URL}/en/portal/facebook_login"
radzi0_0
  • 1,250
  • 2
  • 14
  • 24
0

You can define constant in app/config/constant.php

define('FACEBOOK_LOGIN_URL','http://localhost:8000/en/portal/facebook_login');
define('FACEBOOK_CALLBACK_URL','http://localhost:8000/en/portal/facebook_callback');

echo FACEBOOK_LOGIN_URL;

And so on for other url's , I hope it will solve your problem !

Devdutt Sharma
  • 391
  • 1
  • 2
  • 10