Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs 1.5 / laravel bad request 400

When I do a POST request using my angular app to my laravel api I get an error bad request 400 , however GET requests work normally, also I do POST requests using POSTMAN and it works , here is my code :

$http.get('http://localhost/laravel/datingApp/jobapi/public/api/user/users');

this get request works, this post request doesn't (data is an js object {'email': 'value','password': 'value'}) :

  $http({

            url: 'http://localhost/laravel/datingApp/jobapi/public/api/user/login',
            method: 'POST',
            contentType: "application/json",
            data: data

  }).success(function(data) {

            console.log(data);

  });

also I tried doing that just regular way: $http.post('blabla'); but it doesn't work either :(

edit: sorry didn't include error:

angular.js:12011 POST   
http://localhost/laravel/datingApp/jobapi/public/api/user/login 400 (Bad Request)

(anonymous function)          @ angular.js:12011
sendReq                       @ angular.js:11776
serverRequest                 @ angular.js:11571
processQueue                  @ angular.js:16383
(anonymous function)          @ angular.js:16399
$eval                         @ angular.js:17682
$digest                       @ angular.js:17495
$apply                        @ angular.js:17790
(anonymous function)          @ angular.js:25890
dispatch                      @ jquery.min.js:3
q.handle                      @ jquery.min.js:3
like image 801
Mikail Avatar asked Dec 01 '25 17:12

Mikail


1 Answers

That was a stupid error, but thanks to @piscator I have found it, Laravel by default returns 400 when validation rules are not met , So my input was wrong all the time that is the reason I got 400.

like image 194
Mikail Avatar answered Dec 04 '25 22:12

Mikail



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!