Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

stefanzweifel/screeenly

520 stars
1 code files
View stefanzweifel/screeenly on GitHub

app/Exceptions/Handler.php

Open in GitHub
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Validation\ValidationException;
use Throwable;
 
class Handler extends ExceptionHandler
{
//
protected function invalidJson($request, ValidationException $exception)
{
if ($request->is('api/v1/*')) {
$json = [
'title' => 'An error accoured',
'message' => 'Validation Error: '.collect($exception->errors())->flatten()->first(),
];
} else {
$json = $exception->errors();
}
 
return response()->json($json, $exception->status);
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.