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

amoktar's avatar

Getting server error 500 with api requests when not having token with the request !

Hello guys, I'm having a laravel "laravel/framework": "^8.40", with "laravel/passport": "^10.1", for authenticating api requests and I'm using Postman

I noticed that if I did n't provide the Bearer Token with request to routes, protected with middleware (auth:api) I'm getting a 500 error and If I set the Bearer Token with the request everything goes well !

The same if the token was invalid, getting 500 error below

protected endpoint

Route::middleware('auth:api')->group(function () {
        Route::get('/account', function (Request $request) {
            return $request->user();
        });
});

the error:

Illuminate\Contracts\Container\BindingResolutionException: Target class [App\Http\Controllers\Auth\LoginController] does not exist. in file C:\Users\AMoktar\Documents\code\project\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 875

Thanks

0 likes
9 replies
eterlinden's avatar

Hey @amoktar ,

Try running composer dumpautoload to rebuild your classpaths - that should, as long as the classes do exist, fix your issue.

amoktar's avatar

@eterlinden thanks, the class is exist, and I tried composer dumpautoload but still getting the error

eterlinden's avatar

Ok, so that's not the issue. I just found you a nice link that might help you with the problem. It will explain to you about installing Passport a bit (just to make sure you have it installed correctly) and then go into how to deal with tokens.

This was just quicker than me explaining it ;)

https://blog.logrocket.com/laravel-passport-a-tutorial-and-example-build/

Hope this helps figure things out for you.

1 like
amoktar's avatar

I've rechecked my passport configurations , looks fine! :( I'm not sure what is wrong.

eterlinden's avatar

Can you tell me how you are making the request, what you are using to make, and show me an example of the request you are sending?

Snapey's avatar
Snapey
Best Answer
Level 122

its trying to redirect you to login (which you don't have). Make sure you tell Laravel that you want a application/json response so that it returns the unauthenticated error to you and not a http redirect

make sure you set this Accept header in the postman headers with the request

1 like

Please or to participate in this conversation.