app/Exceptions/Handler.php
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); }}