2016-10-11 3 views
1

AngularJS 양식 및 Laravel을 백엔드로 사용하여 새 사용자를 만들려고하는데 기능이 예상대로 작동하지만 기존 전자 메일 사용자를 확인하는 경우는 예외입니다. 아래는 나의 각 모양 Factory, ControllerngSubmitLaravel 양식 입력 처리를위한 기능입니다.Laravel 및 AngularJS 내에서 기존 전자 메일 확인

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 
    } 
} 

프런트 엔드에 오류 메시지가 표시되지 않는 것 같습니다. 백엔드가 정상적으로 작동하는 것 같습니다.

+0

콘솔에 오류가 표시됩니까? 그것은 실제로 아무것도 발사하고 있습니까? –

+0

@AndyHolmes 콘솔이 비어있는 것 같습니다. –

답변

0

해결했습니다!

내 Laravel 컨트롤러가 엉망이 된 것 같습니다. 아래 코드로 변경 한 후 코드가 제대로 작동하기 시작했습니다.

// 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) { 
     if(res.error) 
     { 
      console.log("error exists"); 
     } 
     $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(count($existingUser) > 0) 
    { 
     return response()->json(['error' => 'User Already Exist with the same email address.']); 
    } else { 
     // save user in model 
    } 
} 

내가 대신이 같은 상황에 직면 누군가를 위해 도움이 ! 빈 condition.Hope과 확인의 Laravel 웅변에서 반환 된 컬렉션 배열을 계산 할 필요가 있었다.