Im working on validation in laravel so below is my code
//error holder
$error = array();
$validator = Validator::make($request->all(),[
'email' => 'email|unique:users',
'username' => 'required|regex:/^[a-zA-Z0-9_]+([-.][a-zA-Z0-9_]+)*$/',
'new_password' => 'required',
'confirm_password' => 'required',
'full_name' => 'required',
'role' => 'required',
'status' => 'required',
]);
if ($validator->fails()){
array_push($error, $validator->messages());
}
$msg = "Ops seems like there's an error: ";
foreach($error as $error_bug){
$msg .= $error_bug . ", ";
}
//return error
return $msg;
so first i created an empty array then next push the error message unto the array and loop through the array of objects and return it to the client. Everything works except there's an ugly thing going, it render me this
Ops seems like there's an error: {"email":["The email has already been taken."]}
as you can see there's bracket and braces which I dont want, i only want to get the message of the error from the validation fail. Any ideas, help?