简体   繁体   English

Laravel/angular - 400 错误请求

[英]Laravel/angular - 400 bad request

I am making an app in ionic and the backend is made in Laravel.我正在用 ionic 制作一个应用程序,后端是用 Laravel 制作的。 I am working on a password reset functionality, and I keep getting the above mentioned error, when I am testing endpoints in chrome.我正在研究密码重置功能,当我在 chrome 中测试端点时,我不断收到上述错误。 This is the code for the contact information function:这是联系信息功能的代码:

    sendContactConfirmation: function(contact, reset) {
      var defer = $q.defer();

      if(reset == 'reset'){
        var endpointUrl = $http.post(AppSettings.apiUrl + "/users/reset", { phone: contact });
      }
      else {
        var endpointUrl = $http.post(AppSettings.apiUrl + "/users", { phone: contact });
      }

      endpointUrl.then(function(result) {
        service.set(result.data.user);
        defer.resolve(result);
      }, function(error) {
        defer.reject(error);
      });

      return defer.promise;
    },

And these are the routes in my Laravel back-end:这些是我的 Laravel 后端中的路由:

Route::group(['jwt.auth', ['except' => ['authenticate']], 'prefix' => 'api', 'namespace' => 'Api'], function() {
    Route::post('authenticate', 'AuthenticateController@authenticate');
    Route::get('authenticate/user', 'AuthenticateController@getAuthenticatedUser');

    Route::post('users', 'UsersController@register');
    Route::post('users/reset', 'UsersController@resetContact');
    Route::put('users/{user}/reset', 'UsersController@resetPassword');
    Route::put('users/{user}', 'UsersController@update');
    Route::put('users/{user}/activate', 'UsersController@activate');
    Route::post('users/{user}/pic', 'UsersController@uploadPicture');
});

And this is the resetContact function:这是 resetContact 函数:

public function resetContact(Request $request)
    {
        $this->validate(
            $request,
            ['phone' => 'required|regex:/^[0-9]{8}$/']
        );

        $user = User::where('phone', $request->get('phone'))->firstOrFail();

        if ($user) {
            try {

                $this->sendValidationCode($user, 'reset');
            }
            catch (\Exception $e) {
                throw new ApiException($e->getMessage(), 500);
            }
        }

        return response()->json([
            'user' => $user,
        ]);
    }

Not sure why do I get this 400 Bad request error for this.不知道为什么我会收到这个 400 Bad request 错误。

When using Laravel JWT make sure you always send the token for all routes under jwt.auth otherwise you will get the error 400 = Token not provided.使用 Laravel JWT 时,请确保始终为 jwt.auth 下的所有路由发送令牌,否则您将收到错误 400 = 未提供令牌。 In ionic make sure your toke is provided on each call to your laravel endpoint to avoid this error.在 ionic 中,请确保在每次调用 laravel 端点时都提供令牌以避免此错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM