Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 Error Reporting Suppression

In Laravel 4, it was easy enough to suppress E_NOTICE messages; I can't seem to be able to do this because if I add

error_reporting(E_ALL ^ E_NOTICE) 

anywhere it simply gets overridden.

This seems to happen around here: (index.php)

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()

);

I have added custom code to handle more "pretty" views of exceptions/errors within Exceptions/Handler.php but I'm struggling to switch off notices (I don't want any of these firing off with notices at all)

  • Yes, the issue should be fixed, I'm aware of this, however this is a case where I'd prefer the notices NOT bombing the app on live (I have a custom logging solution for this), and on dev I'd like the notice to show.
like image 816
ConfusedDevelopment Avatar asked Feb 17 '15 12:02

ConfusedDevelopment


People also ask

How do I turn off error reporting in laravel?

By default, error detail is enabled for your application. This means that when an error occurs you will be shown an error page with a detailed stack trace and error message. You may turn off error details by setting the debug option in your app/config/app. php file to false .

How do I turn on error reporting in laravel?

Through your config/app. php , set 'debug' => env('APP_DEBUG', false), to true . Or in a better way, check out your . env file and make sure to set the debug element to true.

How do I turn off php warnings?

In-depth With the error_reporting() functionerror_reporting(0); To remove all errors, warnings, parse messages, and notices, the parameter that should be passed to the error_reporting function is zero. It would be not practical to have this line of code in each of the PHP files.

What is exception handler in laravel?

When you start a new Laravel project, error and exception handling is already configured for you. The App\Exceptions\Handler class is where all exceptions thrown by your application are logged and then rendered to the user.


2 Answers

In Laravel 5, we can set error_reporting(E_ALL ^ E_NOTICE) inside the AppServiceProviders::boot method:

public function boot()
{
    //set whatever level you want
    error_reporting(E_ALL ^ E_NOTICE);
} 
like image 157
Moppo Avatar answered Oct 03 '22 08:10

Moppo


Are you sure APP_DEBUG in your .env file is set to false in production? That might override your error_reporting() call.

like image 42
Giovanni Casinelli Avatar answered Oct 03 '22 09:10

Giovanni Casinelli