Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GimmeMylanta's avatar

must be an instance of Illuminate\Http\Request, instance of stdClass given

Hey Guys,

I'm having a bit of an issue figuring out how to pass a Request object from my javascript application to my laravel backend.

In my javascript framework i am doing the following;

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

and then passing the formData to my laravel endpoint.

My authenticate function is just a standard;

public function authenticate(Request $request)

The problem is that everytime i try to run my code, i am getting;

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

Does anyone know how I can solve this?

0 likes
5 replies
tisuchi's avatar

I think you have missed this to import on top of your controller-

use Illuminate\Http\Request;
4 likes
GimmeMylanta's avatar

@tisuchi It's already there.

My controller imports are as follows;

namespace App\Http\Controllers;

use JWTAuth;
use App\Models\User;
use JWTAuthException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Tymon\JWTAuth\Exceptions\JWTException;
ralphdns's avatar

remove the use Illuminate\Http\Request; and replace with use Request hope that helps

sujancse's avatar

var formData = new FormData(); is not of type Illuminate\Http\Request; that is why you are getting the error.

Why not try

public function authenticate()
{
    $request = \Input::all();
}

Please or to participate in this conversation.