How to access larvel.env variables inside yourself

I need to ask a stupid question, but my question is: accessing the .env variable inside myself is not from php:

If I have a file .envfor larvel5.4, and I have APP_URLLike this:

APP_ENV=local
APP_KEY=base64:7qLJMqTxrAPk+tLJscVlmrzf2H16tAfbSoCZuleCkxQ=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

and I have a multi config variable, using a 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

There is a way to access APP_URL in the same file as in this case:

FACEBOOK_LOGIN_URL= APP_URL /en/portal/facebook_login

Please, I am a new member, do not give me a minus for this question.

Thank you all

+6
source share
4 answers

There is no way to do this, it just needs to be simple, when 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');
+3
source

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;

URL-, , !

0

you can set the variable as:

Config :: set ('site.name', 'www.example.co')

0
source

While the other answers are correct regarding the use of variables stored in .env. I think it will be more accurate if you do the following:

url(env('FACEBOOK_LOGIN_URL'))

or

url(env('FACEBOOK_CALLBACK_URL'))

url()uses APP_URL, so you do not need to combine variables .env.

0
source

Source: https://habr.com/ru/post/1016752/


All Articles