I am trying to create a new user with AngularJS form and Laravel as backend, the functionality works as expected with exception to checking for users with existing email. Below is my Angular Factory
, Controller
function for ngSubmit
and Laravel
controller function for processing form inputs.
UsersFactory.createNewUser = function(formData) {
return $resource('api/users/create');
}
// controller function to process form
$scope.processCreateUser = function() {
// Add the user via Factory provided route and close the dialog
UsersFactory.createNewUser().save($scope.formData).$promise.then(function(res) {
$scope.formLoading = true;
$timeout(function() {
$scope.close();
},1000);
});
}
// Laravel Controller function
public function store(Request $request)
{
$existingUser = User::where('email',$request->input('email'))->get();
if(!empty($existingUser))
{
return response()->json(['error' => 'User Already Exist with the same email address.']);
} else {
// save user in model
}
}
I cannot seem to display the error message in the front-end, the backend seems to be working fine.