Skip to content

3 Methods to Check If Debug Mode Is Enabled in Laravel

laravel check debug mode

Let’s look at 3 simple methods to check if debug mode is enabled in a Laravel project.

 

 

Check .env file

Let’s start with the first and the most obvious one.

Open the .env file and check the APP_DEBUG variable.

If you choose to change its value, then don’t forget to run the following command to clear out the configuration cache:
php artisan config:cache

App Facade & helper function

Let’s switch to a more programmatic way of checking if debug mode is enabled.

The App Facade provides the hasDebugModeEnabled() method.

In a similar fashion, we can use the app() helper function to get an instance of Application Class that provides the same method.


config() helper function

The config() helper function can also determine if debug mode is enabled.

config('app.debug'); // returns bool

Performance

All 3 methods do their job, but let’s see which one is faster.

Performance-wise, the config() helper is slightly faster.

Happy coding 😊


Let me know what you think about this article in the comments section below.

If you find this article helpful, please share it with others and subscribe to the blog to support me, and receive a bi-monthly-ish e-mail notification on my latest articles.   
  

Comments