rgn
rgn

Reputation: 893

How can I check debug mode on Laravel

I want to see errors when I work in the localhost.

App\Exceptions\handler.php

I Tried:

public function render($request, Exception $exception)
{
    if ($this->isHttpException($exception) && env('APP_DEBUG') === false) {
        return response()->view('errors.404', [], 404);
    } else {
        return parent::render($request, $exception);
    }
}

or;

if ($this->isHttpException($exception) && App::environment('APP_DEBUG') === false)

I tried it as above but it does not work.

Thanks.


APP_DEBUG is set to true in .env

Upvotes: 15

Views: 25220

Answers (5)

Syamsoul Azrien
Syamsoul Azrien

Reputation: 2742

Since Laravel version 8 and above:

You can just do like this:

$is_debug_mode = app()->hasDebugModeEnabled();

. .

Upvotes: 1

Dan
Dan

Reputation: 5358

You may use Application::hasDebugModeEnabled() as an abstraction around the hardcoded config key.

Since Laravel 10, the method was also added to the Application contract.

Call it by either injecting the Illuminate\Contracts\Foundation\Application contract into the constructor or by using the app() helper.

Upvotes: 5

insign
insign

Reputation: 5773

To avoid big problems with cache, the right way to check is:

config('app.debug') == false

Upvotes: 58

user8271849
user8271849

Reputation: 47

Try to change

env('APP_DEBUG') === false

to

env('APP_DEBUG') == false

Upvotes: -1

Ferran
Ferran

Reputation: 142

In your .env file you should have:

APP_DEBUG=true

Upvotes: -7

Related Questions