Creating a Laravel form object using Ext Direct

100 Views Asked by At

Im using ExtDirect in my Frontend Ext project to interact with my Laravel API.

I have a login method in my AuthController which uses the Request object like so;

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'));
}

Then my javascript is like this;

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

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

When I run my code, I get the following error;

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

How can I change my formdata object to be compatible with the Laravel request object?

Any help would be greatly appreciated.

0

There are 0 best solutions below