Laravel adds php notices to response content

Viewed 84

I have the issue that laravel (version 8) adds php notices I get to the response as html string. This is really annoying because the response should be json and now I have string that contains html and json. This is how the response looks:

<br />\n<b>Notice</b>:  Unknown: file created in the system's temporary directory in <b>Unknown</b>   on line <b>0</b><br />
{\"type\":[\"The type field is required.\"]}

Any idea how to disable this behaviour ?

I already tried using phps error_reporting() function. Even with APP_DEBUG=false this occurs.

1 Answers

I just hit this too, I fixed it by setting the php display_errors runtime config value to off. See https://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors


More specifically, on my macos/Brew PHP setup it was by editing

/usr/local/etc/php/8.0/php-fpm.d/www.conf

and removing the commenting-semicolon on this line

;php_flag[display_errors] = off

and restarting the php@8.0 service

brew services restart php@8.0

On other platforms like Ubuntu, it might be found by grepping under /etc/php for display_errors

Related