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

Akash_kushwaha's avatar

Passport API auth middleware is giving error.

Hello everyone, I'm creating an API with authentication of Laravel Passport. but I'm getting this error.

					Array to string conversion in file /var/www/html/laravel-passport-api/vendor/laravel/framework/src/Illuminate/Routing/ResourceRegistrar.php on line 630

whenever I'm adding middleware('auth:api') in the api route file.

https://tinyurl.com/243yns7w

0 likes
1 reply
AddWebContribution's avatar

@akash_kushwaha You are probably confusing the syntax for regular routes with the syntax for resource controllers.

For resource controllers you have to pass the class name as a string:

  Route::resource('/products',  [Productcontroller::class])->middlerware('auth:api');
// remove the array from controller
  Route::resource('/products',  PrderController::class)->middlerware('auth:api');
1 like

Please or to participate in this conversation.