📖 Scenario: You are building a Laravel web application. Sometimes errors happen, and you want to see detailed error messages to fix problems quickly.
🎯 Goal: Learn how to enable Laravel's debug mode and display detailed error information during development.
📋 What You'll Learn
Create a Laravel configuration file change to enable debug mode
Add a helper variable to control debug mode
Use the debug mode setting to conditionally show error details
Complete the setup so Laravel shows detailed error pages when debug mode is on
💡 Why This Matters
🌍 Real World
Developers use debug mode in Laravel to see detailed error messages during development. This helps find and fix bugs faster.
💼 Career
Knowing how to enable and use debug mode is essential for Laravel developers to troubleshoot issues and ensure smooth application development.
Progress0 / 4 steps
1
Set APP_DEBUG to true in .env
Open the .env file and set the variable APP_DEBUG to true exactly like this: APP_DEBUG=true
Laravel
Hint
Find the line starting with APP_DEBUG= and change its value to true.
2
Create a variable $debug in config/app.php
In the config/app.php file, create a variable called $debug and set it to the value of env('APP_DEBUG', false) exactly like this: $debug = env('APP_DEBUG', false);
Laravel
Hint
Use the env helper to read APP_DEBUG and assign it to $debug.
3
Use $debug to conditionally show error details in a Blade view
In a Blade view file, use an @if directive with the variable $debug to show a message Debug mode is ON only when $debug is true. Write exactly: @if($debug) Debug mode is ON @endif
Laravel
Hint
Use Blade's @if directive to check $debug and show the message.
4
Complete Laravel debug mode setup to show detailed error pages
Ensure the APP_DEBUG variable is set to true in .env and the $debug variable is used in your app configuration and views so Laravel shows detailed error pages when errors happen.
Laravel
Hint
Make sure the environment and config use APP_DEBUG=true and your views check $debug to show debug info.
Practice
(1/5)
1. What does setting APP_DEBUG=true in Laravel's .env file do?
easy
A. Shows detailed error messages to help find bugs
B. Disables all error messages
C. Automatically fixes bugs in the code
D. Prevents the application from running
Solution
Step 1: Understand the purpose of APP_DEBUG
APP_DEBUG controls whether Laravel shows detailed error messages or not.
Step 2: Effect of setting APP_DEBUG=true
When true, Laravel shows detailed error info to help developers find and fix bugs.
Final Answer:
Shows detailed error messages to help find bugs -> Option A
Quick Check:
APP_DEBUG=true means detailed errors shown [OK]
Hint: True means show errors, false hides them [OK]
Common Mistakes:
Thinking it fixes bugs automatically
Believing it disables errors
Confusing it with app running status
2. Which of the following is the correct way to enable debug mode in Laravel?
easy
A. Set APP_DEBUG=false in .env
B. Set APP_DEBUG=true in .env
C. Add debug_mode=on in config/app.php
D. Run php artisan debug:on in terminal
Solution
Step 1: Locate where debug mode is set
Laravel uses the .env file to set environment variables like APP_DEBUG.
Step 2: Correct value to enable debug
Setting APP_DEBUG=true enables debug mode; false disables it.
Final Answer:
Set APP_DEBUG=true in .env -> Option B
Quick Check:
Enable debug by APP_DEBUG=true [OK]
Hint: Enable debug by setting APP_DEBUG=true in .env [OK]
Common Mistakes:
Setting APP_DEBUG=false to enable debug
Trying to enable debug in config/app.php
Using artisan commands that don't exist
3. Given the following .env setting: APP_DEBUG=false What will Laravel show when an error occurs?
medium
A. A detailed error page with stack trace
B. The application will crash without any message
C. A simple generic error page without details
D. Laravel will automatically fix the error
Solution
Step 1: Check APP_DEBUG value
APP_DEBUG is set to false, which disables detailed error messages.
Step 2: Laravel's behavior with APP_DEBUG=false
Laravel shows a simple generic error page to avoid exposing sensitive info.
Final Answer:
A simple generic error page without details -> Option C