Laravel has a .env file that contains various variables. Is there a way to get all the variables in one line of PHP code? I don't want to write
echo env('APP_DEBUG')
echo env('APP_URL')
etc...
I have tried
env("*")
env("*")
but none works.
Laravel has a .env file that contains various variables. Is there a way to get all the variables in one line of PHP code? I don't want to write
echo env('APP_DEBUG')
echo env('APP_URL')
etc...
I have tried
env("*")
env("*")
but none works.
This should work:
$_ENV; // gives all env variables.
To get a single env variable:
$_ENV['VARIABLE'];
The only safe way for reading all env()
attributes is to use Dotenv
directly :
$env = Dotenv\Dotenv::createArrayBacked(base_path())->load()
This method is usable on every environment : cli, dispatched jobs, without proper web server and even if php.ini is ignoring env.
$env = \Dotenv\Dotenv::create(base_path())->load();
–
Perfumery 'FOO'
key in this output will match env('FOO')
. For example, if the configuration is cached via php artisan config:cache
, calls to the env()
helper may return values that differ from those output via this command. Just a heads-up. –
Undry You can do the following:-
php artisan tinker
$_ENV
© 2022 - 2024 — McMap. All rights reserved.
.env
file or all environment variables? And why would you want this? – Cheesy