Home > Back-end >  Laravel 9 custom FormRequest throws "Object of type Illuminate\Session\Store is not callable&
Laravel 9 custom FormRequest throws "Object of type Illuminate\Session\Store is not callable&

Time:02-17

Im testing out the new laravel 9 and I sadly come across this surprise.

After using PHP artisan make:request UpdateUserRequest and setting this as my request class on the incoming update function, this error happens:

[2022-02-09 12:42:08] local.ERROR: Object of type Illuminate\Session\Store is not callable {"userId":2,"exception":"[object] (Error(code: 0): Object of type Illuminate\\Session\\Store is not callable at /app/vendor/symfony/http-foundation/Request.php:698)

My code

UserController:

public function update(UpdateUserRequest $request){}

UpdateUserRequest:

{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
        ];
    }
}

What I did so far to try to fix the problem is see when it happens. When I change the extended class of my UpdateUserRequest from FormRequest to Request the error doesn't happen. so it seems to be in FormRequest.

Added the 'web' middleware to my routes also did not solve the problem (suggestion from the internet)

I can ofcourse create my own class that doesn't extend anything and just validates it by using the regular Request class but that's ofcourse not how its supposed to work.

Complete stacktrace:

Error:
Object of type Illuminate\Session\Store is not callable

  at /app/vendor/symfony/http-foundation/Request.php:698
  at Symfony\Component\HttpFoundation\Request->getSession()
     (/app/vendor/laravel/framework/src/Illuminate/Http/Request.php:424)
  at Illuminate\Http\Request::createFrom(object(Request), object(UpdateUserRequest))
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php:34)
  at Illuminate\Foundation\Providers\FormRequestServiceProvider->Illuminate\Foundation\Providers\{closure}(object(UpdateUserRequest), object(Application))
     (/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:1269)
  at Illuminate\Container\Container->fireCallbackArray(object(UpdateUserRequest), array(object(Closure)))
     (/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:1216)
  at Illuminate\Container\Container->fireResolvingCallbacks('App\\Http\\Requests\\UpdateUserRequest', object(UpdateUserRequest))
     (/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:778)
  at Illuminate\Container\Container->resolve('App\\Http\\Requests\\UpdateUserRequest', array(), true)
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:854)
  at Illuminate\Foundation\Application->resolve('App\\Http\\Requests\\UpdateUserRequest', array())
     (/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:694)
  at Illuminate\Container\Container->make('App\\Http\\Requests\\UpdateUserRequest', array())
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:839)
  at Illuminate\Foundation\Application->make('App\\Http\\Requests\\UpdateUserRequest')
     (/app/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php:79)
  at Illuminate\Routing\ControllerDispatcher->transformDependency(object(ReflectionParameter), array('user' => '10'), object(stdClass))
     (/app/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php:48)
  at Illuminate\Routing\ControllerDispatcher->resolveMethodDependencies(array('user' => '10'), object(ReflectionMethod))
     (/app/vendor/laravel/framework/src/Illuminate/Routing/RouteDependencyResolverTrait.php:28)
  at Illuminate\Routing\ControllerDispatcher->resolveClassMethodDependencies(array('user' => '10'), object(UserController), 'update')
     (/app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:41)
  at Illuminate\Routing\ControllerDispatcher->dispatch(object(Route), object(UserController), 'update')
     (/app/vendor/laravel/framework/src/Illuminate/Routing/Route.php:261)
  at Illuminate\Routing\Route->runController()
     (/app/vendor/laravel/framework/src/Illuminate/Routing/Route.php:204)
  at Illuminate\Routing\Route->run()
     (/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:695)
  at Illuminate\Routing\Router->Illuminate\Routing\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:128)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/spatie/laravel-permission/src/Middlewares/RoleMiddleware.php:27)
  at Spatie\Permission\Middlewares\RoleMiddleware->handle(object(Request), object(Closure), 'superadmin')
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:50)
  at Illuminate\Routing\Middleware\SubstituteBindings->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php:44)
  at Illuminate\Auth\Middleware\Authenticate->handle(object(Request), object(Closure), 'web')
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php:44)
  at Illuminate\Auth\Middleware\Authenticate->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:78)
  at Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49)
  at Illuminate\View\Middleware\ShareErrorsFromSession->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:121)
  at Illuminate\Session\Middleware\StartSession->handleStatefulRequest(object(Request), object(Store), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:64)
  at Illuminate\Session\Middleware\StartSession->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37)
  at Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:67)
  at Illuminate\Cookie\Middleware\EncryptCookies->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103)
  at Illuminate\Pipeline\Pipeline->then(object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:697)
  at Illuminate\Routing\Router->runRouteWithinStack(object(Route), object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:672)
  at Illuminate\Routing\Router->runRoute(object(Request), object(Route))
     (/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:636)
  at Illuminate\Routing\Router->dispatchToRoute(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:625)
  at Illuminate\Routing\Router->dispatch(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:167)
  at Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:128)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21)
  at Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php:31)
  at Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21)
  at Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php:40)
  at Illuminate\Foundation\Http\Middleware\TrimStrings->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27)
  at Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php:86)
  at Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/fruitcake/laravel-cors/src/HandleCors.php:38)
  at Fruitcake\Cors\HandleCors->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php:39)
  at Illuminate\Http\Middleware\TrustProxies->handle(object(Request), object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167)
  at Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103)
  at Illuminate\Pipeline\Pipeline->then(object(Closure))
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:142)
  at Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(object(Request))
     (/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:111)
  at Illuminate\Foundation\Http\Kernel->handle(object(Request))
     (/app/public/index.php:52)     

CodePudding user response:

This was indeed no laravel 9 issue. This issue was from upgrading laravel-dev to official release.

Since there was not that much code made, I decided to clone the new laravel 9 repo, and push my changes manually to this new repo. Then all worked fine.

  • Related