-
In laravel 10 or below I can catch all error with method report by App\Exceptions\Handler::report() public function report(Throwable $e)
{
parent::report($e);
$data = [
'method' => request()->getMethod(),
'message' => $e->getMessage(),
'user' => auth()->id(),
'data' => request()->all(),
];
if ($e instanceof ValidationException) {
$data['errors'] = $e->errors();
}
Log::channel('daily')->info(json_encode($data, JSON_PRETTY_PRINT));
} how about laravel 11? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
It's in the documentation. |
Beta Was this translation helpful? Give feedback.
-
In Laravel 11, the namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException;
class Handler extends ExceptionHandler
{
/**
* Report or log an exception.
*
* @param \Throwable $e
* @return void
*/
public function report(Throwable $e)
{
parent::report($e);
$data = [
'method' => request()->getMethod(),
'message' => $e->getMessage(),
'user' => auth()->id(),
'data' => request()->all(),
];
if ($e instanceof ValidationException) {
$data['errors'] = $e->errors();
}
Log::channel('daily')->info(json_encode($data, JSON_PRETTY_PRINT));
}
} Make sure to review the Laravel 11 upgrade guide for any specific changes or new features related to exception handling. The core concepts for customizing error reporting should remain consistent. |
Beta Was this translation helpful? Give feedback.
Actually I have solved it, just changed report() to render()
Remember my problem, all errors other than status code 20…