我在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请求对象兼容?
任何帮助将不胜感激。