REST API in Laravel when validating the request

these code will help you, working for me.

$response = array('response' => '', 'success'=>false);
$validator = Validator::make($request->all(), $rules);

if ($validator->fails()) {
  $response['response'] = $validator->messages();
} else {
//process the request
}

return $response;

Leave a Comment