Skip to content
Advertisement

Laravel does not read .env variables when there is a # character

In Laravel 7 when I do a simple:

$test_secret = env('TEST_SECRET');
echo 'Secret : ' . $test_secret;
exit;

the output is always:

Secret: 123

And my .env file is:

APP_NAME=Laravel
APP_ENV=local
TEST_SECRET=123#456#789

I am waiting for a response : “Secret: 123#456#789”. And don’t understand why I receive only “Secret: 123”.

I know it is a trivial question, but I am on this problem…

Thanks

Advertisement

Answer

# is used to declare a comment in the .env file. Wrap the var’s value in quotes.

TEST_SECRET="123#456#789"
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement