2016-06-09 1 views
0

각도로 로그인하고 싶지만 폼을 제출하자마자 콘솔 POST에서이 오류가 발생합니다 http://localhost/angulav/public/auth 500 (내부 서버 오류). 각도 경로 오류 - POST http : // localhost/angulav/public/auth 500 (내부 서버 오류)

내 경로

Route::any('/', function() { 
    return view('layout.master'); 
    })->where('path', '.+'); 

Route::post('/auth', '[email protected]'); 

이 내 userController이다 JS

angular.module('myApp').controller('userController', ['$scope', '$http', function($scope, $http){ 
angular.extend($scope, { 
    doLogin: function(loginForm) { 
    $http({ 
     headers: {'Content-Type': 'application/json'}, 
     url: 'auth', 
     method: "POST", 
      data: { 
      username: $scope.login.username, 
     password: $scope.login.password 
      } 
    }).success(function(response){ 
     console.log(response); 
      }); 
      } 
}); 

이 내 HTML

<form class="" ng-submit="doLogin(loginForm)"> 
     <div class="form-group"> 
     <label for="username">Username:</label> 
     <input id="username" class="form-control" ng-model="login.username" type="text" name="username" placeholder="Enter username"> 
     </div> 
    <div class="form-group"> 
     <label for="password">Password:</label> 
     <input id="password" class="form-control" ng-model="login.password" type="password" name="password" placeholder="Enter username"> 
     </div> 
     <div class="form-group"> 
      <input class="btn btn-primary pull-right" id="username" type="submit" value="Submit"> 
     </div> 
</form> 

입니다 이것은 내 usercontroller.php입니다

public function login(Request $request) 
    { 
    $user_data = [ 
    'username' => $request->input('username'), 
    'password' => $request->password('password') 
    ]; 

    if (Auth::attempt($user_data)) { 
     return response(Auth::user(), 201); 
    } else { 
     return response('username and password do not match', 403); 
    } 
} 
+0

우편 배달부에서 사용해 보셨습니까? –

+0

@PareshGami : 우편 배달부 란 무엇입니까? – nana

+0

포스트맨은 개발을 시작하기 때문에 API를 테스트 할 수있는 도구입니다. 크롬을위한 Google 우체부 검색 –

답변

0

콘텐츠 유형이 json이지만 개체를 ​​통해 전송합니다. 당신이 작동하지 않는 경우, application/x-www-form-urlencoded 대신 application/json에 헤더 콘텐츠 형식의 정보를 변경하려고 한 다음 데이터를 구문 분석

data: JSON.stringify({ 
     username: $scope.login.username, 
     password: $scope.login.password 
    }) 

에 그것을

data: { 
     username: $scope.login.username, 
     password: $scope.login.password 
    } 

변화가 는 $에 반대 httpParamSerializer 기능은 아래를 참조하십시오. (dont는 그것을 주입하는 것을 잊는다).

data: $httpParamSerializer({ 
     username: $scope.login.username, 
     password: $scope.login.password 
    })