NicuVlad
NicuVlad

Reputation: 2601

Laravel: how to cache config files properly

I'm using Laravel 8.0 in my application and I added a new .env variable:

APP_URL_FRONT=https://tmsv00008:6204

And how I use it:

To access the project use the following link: <a href="{{ env('APP_URL_FRONT') }}/projects/{{ $project->id }}">LINK</a> 

When I deploy the application I cache the config files:

php artisan config:cache

But the env files is not visible and the strange thing is that if I execute:

php artisan config:clear

The variable is visible. What I'm doing wrong? Because it doesn't make sense to me.

Also, in this article they suggest to execute the commands in this order:

php artisan config:cache
php artisan config:clear

But this doesn't make sense to me. Shouldn't be the other way around? And I think the cache commands also clears the cache first.

Upvotes: 0

Views: 666

Answers (1)

Alberto
Alberto

Reputation: 12899

The env() function is strongly recommended to be used only in configuration file, since caching the configurations, will make the env function to return null

In other words, crate a configuration file, with that environment variable, or add it to an existing one

It's hidden in an old update guide this "note"

Upvotes: 2

Related Questions