After updating Laravel to v10 and Passport to v11 and PHP to 8.2 - my laravel application stopped working correctly. All "normal" endpoints (e.g. /api/user
) working. But all v2 endpoints (e.g. /api/v2/user
) that are using the auth middleware do not. I don't receive any response. It just says "Socket hang up".
I tried to debug the application but there is no error thrown. Also, the pointer has no access to the actual function in my UserController. It looks like that this is the last Line of code that is getting executed before I receive the "socket hang up":
// vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php
return (new Pipeline($this->app))
->send($request)
->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware)
->then($this->dispatchToRouter());
This is my composer file:
"require": {
"php": "^8.2",
"alymosul/laravel-exponent-push-notifications": "^4.0",
"awobaz/compoships": "^2.0",
"barryvdh/laravel-dompdf": "^2.0",
"eluceo/ical": "^0.16.0",
"glorand/laravel-model-settings": "^6.0",
"guzzlehttp/guzzle": "^7.0.1",
"guzzlehttp/psr7": "^2.4",
"intervention/image": "^2.5",
"laravel/cashier": "^14.4",
"laravel/framework": "^10.0",
"laravel/helpers": "^1.1",
"laravel/passport": "^11.0",
"laravel/tinker": "^2.7.3",
"laravel/ui": "^4.0",
"lcobucci/jwt": "^4.1.5",
"owen-it/laravel-auditing": "^13.0.5",
"predis/predis": "^1.1",
"sentry/sentry-laravel": "^3.1",
"spatie/laravel-permission": "^5.7.0",
"symfony/process": "^6.0"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.8",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.0"
},
To understand how my API versioning is working, here is a quick overview:
I have a APIVersion Middleware:
public function handle(Request $request, Closure $next, $guard)
{
if ($guard != 'v1') {
// Morph user model
$apiVersion = $guard == '' ? '' : ('\\' . strtoupper($guard) . '\\');
}
config(['app.api.version' => $guard]);
return $next($request);
}
In my RouteServiceProvider I have this code here:
Route::group([
'middleware' => ['api', 'api_version:v1'],
'namespace' => "{$this->namespace}",
'prefix' => 'api',
], function ($router) {
require base_path('routes/api.php');
});
Route::group([
'middleware' => ['api', 'api_version:v2'],
'namespace' => "{$this->namespace}\V2",
'prefix' => 'api/v2',
], function ($router) {
require base_path('routes/api/api_v2.php');
});
Because I use a updated user model, I also have a second provider in my auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
'api_v2' => [
'driver' => 'passport',
'provider' => 'users_v2',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => 'App\Models\Base\User',
],
'users_v2' => [
'driver' => 'eloquent',
'model' => 'App\Models\V2\Base\User',
],
],
Finally, In my api_V2.php routes file, I use this group
Route::group(['middleware' => ['auth:api_v2']], function () {
I think the error has something to do with Laravel passport, because if I create a Route in my api_v2 outside the auth:api_v2 scope, the endpoint returns the data. I already checked the Upgrade guide for Laravel 11, but I can't find the problem.
The problem happens in "glorand/laravel-model-settings": "^6.0"
. The package can't handle inheritance in the HasSettings
Trait.
There is already an open PR for this issue.