Send custom JSON error response in Laravel

Ravi Teja
Ravi Teja
Mar 22 · 1 min read

Instead of using a validator, you can send custom JSON error responses in Laravel. If you are using axios library, the catch() method will grab the response.

if ($some_check_here) {
return response()->json([
'errors' => [ 'contact_type' => [ 'You must give either valid email or phone number' ] ] ], 422);
}
Ravi Teja

Written by

Ravi Teja

Full stack developer. Entrepreneur.