use IlluminateSupportFacadesValidator;
// ....
// On your Store function
public function store(Request $request, $id)
// Validation
$validator = Validator::make($request, [
'name' => 'required',
'username' => 'required|unique:users,username,NULL,id,deleted_at,NULL',
'email' => 'nullable|email|unique:users,email,NULL,id,deleted_at,NULL',
'password' => 'required',
]);
// Return the message
if($validator->fails()){
return response()->json([
'error' => true,
'message' => $validator->errors()
]);
}
// ....
}
// On your Update function
public function update(Request $request, $id)
{
// Validation
$validator = Validator::make($input, [
'name' => 'required',
'username' => 'required|unique:users,username,' . $id. ',id,deleted_at,NULL',
'email' => 'nullable|email|unique:users,email,' . $id. ',id,deleted_at,NULL',
'roles' => 'required'
]);
// Return the message
if($validator->fails()){
return response()->json([
'error' => true,
'msg' => $validator->errors()
]);
}
// ....
}