Env() in Laravel 5 – 8.x (current) Always Returns Null

Env() in Laravel 5 - 8.x (current) Always Returns Null
Written by @kiosmerdeka

After you cached the configuration, the env(…) function will no longer function. (from Laravel 5.2 to the current 8.x)

According to the Laravel documentation

If you use the config:cache command during deployment, you must ensure that the env function is only called from within your configuration files and not from anywhere else in your application.

As a result, the correct response would be to:

If you’re calling env from within your application, it’s highly recommended that you add proper configuration values to your configuration files and call env from there instead, allowing you to convert your env calls to config calls.

But for a quick fix, try this:

php artisan configuration:clear

And it should now be clear why config:cache did not help, despite the fact that it clears the config prior to caching.

Baca juga  How To Add Row Number Or Serial No In Laravel Datatable

Leave a Comment