3 Methods to Check If Debug Mode Is Enabled in Laravel
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.
.env file and check the
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.
App Facade provides the
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
config() helper function can also determine if debug mode is enabled.
config('app.debug'); // returns bool
All 3 methods do their job, but let’s see which one is faster.
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.