2

我在我的 Frontend Ext 项目中使用 ExtDirect 与我的Laravel API进行交互。

我有一个登录方法,AuthController它像这样使用 Request 对象;

public function login(Request $request)
{
    $validator = Validator::make($request->all(), [
        'email' => 'required|string|email|max:255',
        'password'=> 'required|string|min:6'
    ]);

    if ($validator->fails()) {
        return response()->json($validator->errors(), 400);
    }

    $credentials = $request->only('email', 'password');

    try {

        if (! $token = JWTAuth::attempt($credentials)) {
            return response()->json(['error' => 'Invalid Credentials'], 401);
        }

    } catch (JWTException $e) {

        return response()->json(['error' => 'Could not create token'], 500);

    }

    return response()->json(compact('token'));
}

然后我的javascript是这样的;

var formData = new FormData();
formData.append("email", username);
formData.append("password", password);

Ext.rpc.Auth.login(formData, function(response) {
    console.log(response);
});

当我运行我的代码时,我收到以下错误;

Argument 1 passed to App\Http\Controllers\AuthController::login() must be an instance of Illuminate\Http\Request, instance of stdClass given

如何更改我的 formdata 对象以与 Laravel 请求对象兼容?

任何帮助将不胜感激。

4

0 回答 0