marsuch's avatar

check debug mode

Hi, I just wonder if laravel doesn't have a built-in function to check how debug mode is set. The point is that I need to have some functions in the project commonly accessible. But for production I want them to be subject to some protection. So I just blew up the condition

if (env('APP_DEBUG') === true) {
            $statement = null;
        }
        elseif (env('APP_DEBUG') === false) {
            $statement = true;
        }

So my question is: Has it laravel treated somehow internally? I ask because I plan to modify the condition, expand it and create a helper from it.

0 likes
4 replies
MichalOravec's avatar

Instead of

env('APP_DEBUG')

use

config('app.debug')

From docs: https://laravel.com/docs/7.x/configuration#configuration-caching

If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function will return null.

$statement = config('app.debug') ? null : true;
Snapey's avatar

Its not advised to use env in your code, use the config() helper

marsuch's avatar

OK, thanks for the advice. But back to the point, is there such a function?

Please or to participate in this conversation.