How to access the laravel .env variables inside itself

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.


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

Tags:

Php

Laravel