20

How do I access the debug variable in app/config/app.php from my controller to see if I am in debug mode?

<?php                                                                                                                
                                                                                                                     |
  /*                                                                                                                 |        if ( $this->user->id )
  |--------------------------------------------------------------------------                                        |        {
  | Application Debug Mode                                                                                           |            // Save roles. Handles updating.
  |--------------------------------------------------------------------------                                        |            $this->user->saveRoles(Input::get( 'roles' ));
  |                                                                                                                  |
  | When your application is in debug mode, detailed error messages with                                             |            // Redirect to the new user page
  | stack traces will be shown on every error that occurs within your                                                |            return Redirect::to('admin/users/'.$this->user->id)->with('success', Lang::get('admin/users/messages.cre
  | application. If disabled, a simple generic error page is shown.                                                  |ate.success'));
  |                                                                                                                  |        }
  */                                                                                                                 |  else
                                                                                                                     |  {
  'debug' => true,    

2 Answers 2

38

You can use the helper function config (Laravel 5+).

$debug = config('app.debug');

Laravel 4.2:

$debug = Config::get('app.debug');
Sign up to request clarification or add additional context in comments.

2 Comments

I got undefined function config()...I am on Laravel 4.2.
In the view you can also easily use it just like that. Helpful if you want to display a DEBUG MODE label or something so you don't lose time because you confused the tabs and you're actually on the live server :)
4

This question already has right answer, I just wanted to add that doing it with environmental variables is a better option:

'debug' => env('APP_DEBUG', false),

In .env file:

APP_ENV=local

3 Comments

I saw some suggestions to do this, but I am not sure why this is better. It looks more complicated and confusing than using the existing variable. Could you explain?
Mainly it is better because, you can add .env file to .gitignore file and this way you can have your machine specific usernames and passwords, without sharing it to version control system to others, while app.php file needs to be committed and publicly shared.
@Phil it's also better because you should store all your credentials and other constant stuff in your .env file. You'll notice that all of your configuration settings are like ...=>env('whatever','') in app.php or database.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.