0

After Laravel project upgrade to PHP8 and laravel 9 on the all API endpoints started getting: There is currently no session available.

  • Upgrade was made from laravel 8 to laravel 9.
  • PHP was upgraded from 7.4 to 8.1

Full backtrace:

{
   "message": "There is currently no session available.",
   "status_code": 500,
   "debug": {
       "line": 515,
       "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Http/Request.php",
       "class": "Symfony\\Component\\HttpFoundation\\Exception\\SessionNotFoundException",
       "trace": [
           "#0 /var/www/html/vendor/dingo/api/src/Http/Request.php(39): Illuminate\\Http\\Request->getSession()",
           "#1 /var/www/html/vendor/dingo/api/src/Http/Middleware/Request.php(99): Dingo\\Api\\Http\\Request->createFromIlluminate(Object(Illuminate\\Http\\Request))",
           "#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
           "#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
           "#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
           "#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))",
           "#6 /var/www/html/public/index.php(52): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))",
           "#7 {main}"
       ]
   }
}

Project is dockerized and Dockerfile's were upgraded to php-8.1-apache. Also dependencies fixed after running composer update

These are the most important composer.json requires:

 "php": "^8.1",
 "dingo/api": "dev-l9-compatibility",
 "laravel/framework": "^9.0",
....

It seems to me that error comes from the dingo api:

Illuminate/HTTP/Request.php line 514:

    public function getSession(): SessionInterface
    {
        return $this->hasSession()
                    ? new SymfonySessionDecorator($this->session())
                    : throw new SessionNotFoundException;
    }
Tadis
  • 41
  • 1
  • 8
  • Not enough information, please refer to [ask] and edit your question. – N69S May 12 '22 at 12:43
  • Added some more info about composer.json requires. – Tadis May 12 '22 at 12:51
  • From which version did you upgrade from? what line tried to recover the sessions while being in a stateless environment? – N69S May 12 '22 at 12:56
  • Upgrade was made from laravel 8 to laravel 9. PHP was upgraded from 7.4 to 8.1 . It seems that error is coming from the `dingo` api Illuminate/HTTP/Request.php line 514. However it is not enough info for me to figure out how to solve this error. – Tadis May 13 '22 at 05:57
  • check the backtrace till you find something unusual. Can you also check your code if you used the method `getSession()` from `Illuminate\Http\Request` or the helper `request()` ? – N69S May 13 '22 at 08:05

1 Answers1

1

Was able to fix with this composer dependency for dingo api:

"api-ecosystem-for-laravel/dingo-api": "dev-laravel-9-support"
Tadis
  • 41
  • 1
  • 8