skip to Main Content

I just upgraded to Laravel 9 from v8 and suddenly I’m starting to get this error,

Error: The script tried to call a method on an incomplete object. Please ensure that the class definition "LaravelSerializableClosureSerializableClosure" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide an autoloader to load the class definition
#35 /vendor/laravel/framework/src/Illuminate/Queue/CallQueuedClosure.php(68): IlluminateQueueCallQueuedClosure::handle
#34 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): IlluminateContainerBoundMethod::IlluminateContainer{closure}
#33 /vendor/laravel/framework/src/Illuminate/Container/Util.php(40): IlluminateContainerUtil::unwrapIfClosure
#32 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): IlluminateContainerBoundMethod::callBoundMethod
#31 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): IlluminateContainerBoundMethod::call
#30 /vendor/laravel/framework/src/Illuminate/Container/Container.php(610): IlluminateContainerContainer::call
#29 /vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): IlluminateBusDispatcher::IlluminateBus{closure}
#28 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): IlluminatePipelinePipeline::IlluminatePipeline{closure}
#27 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): IlluminatePipelinePipeline::then
#26 /vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): IlluminateBusDispatcher::dispatchNow
#25 /vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(118): IlluminateQueueCallQueuedHandler::IlluminateQueue{closure}
#24 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): IlluminatePipelinePipeline::IlluminatePipeline{closure}
#23 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): IlluminatePipelinePipeline::then
#22 /vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(120): IlluminateQueueCallQueuedHandler::dispatchThroughMiddleware
#21 /vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): IlluminateQueueCallQueuedHandler::call
#20 /vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): IlluminateQueueJobsJob::fire
#19 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(406): IlluminateQueueWorker::process
#18 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(356): IlluminateQueueWorker::runJob
#17 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(158): IlluminateQueueWorker::daemon
#16 /vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(116): IlluminateQueueConsoleWorkCommand::runWorker
#15 /vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(100): IlluminateQueueConsoleWorkCommand::handle
#14 /vendor/laravel/horizon/src/Console/WorkCommand.php(51): LaravelHorizonConsoleWorkCommand::handle
#13 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): IlluminateContainerBoundMethod::IlluminateContainer{closure}
#12 /vendor/laravel/framework/src/Illuminate/Container/Util.php(40): IlluminateContainerUtil::unwrapIfClosure
#11 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): IlluminateContainerBoundMethod::callBoundMethod
#10 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): IlluminateContainerBoundMethod::call
#9 /vendor/laravel/framework/src/Illuminate/Container/Container.php(610): IlluminateContainerContainer::call
#8 /vendor/laravel/framework/src/Illuminate/Console/Command.php(136): IlluminateConsoleCommand::execute
#7 /vendor/symfony/console/Command/Command.php(298): SymfonyComponentConsoleCommandCommand::run
#6 /vendor/laravel/framework/src/Illuminate/Console/Command.php(121): IlluminateConsoleCommand::run
#5 /vendor/symfony/console/Application.php(1015): SymfonyComponentConsoleApplication::doRunCommand
#4 /vendor/symfony/console/Application.php(299): SymfonyComponentConsoleApplication::doRun
#3 /vendor/symfony/console/Application.php(171): SymfonyComponentConsoleApplication::run
#2 /vendor/laravel/framework/src/Illuminate/Console/Application.php(93): IlluminateConsoleApplication::run
#1 /vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): IlluminateFoundationConsoleKernel::handle
#0 /artisan(37): null

The error is coming from the following file, line 33 which is dispatch(...):

<?php

namespace AppLogging;

use AppModelsHttpLog;
use IlluminateHttpRequest;

class CustomLogWriter implements SpatieHttpLoggerLogWriter
{
    public function shouldLogRequest(Request $request): bool
    {
        if ($request->hasFile('file')) {
            return false;
        }

        # default 
        // return in_array(strtolower($request->method()), ['post', 'put', 'patch', 'delete']);

        # firehose
        return true;
    }

    public function logRequest(Request $request)
    {
        if (config('feature.logAllHttpRequests')) {

            $log = [];
            $log['method'] = $request->getMethod();
            $log['url'] = $request->getPathInfo();
            $log['headers'] = json_encode($request->headers->all());
            $log['body'] = json_encode($request->except(config('http-logger.except')));

            dispatch(function () use ($log) {
                $newLog = new HttpLog;
                $newLog->url = $log['url'];
                $newLog->method = $log['method'];
                $newLog->headers = $log['headers'];
                $newLog->body = $log['body'];
                $newLog->created_at = now();
                $newLog->save();
            });
        }
    }
}

What do you think I am doing wrong?

Laravel version: 9.11.0
PHP version: 8.0.18

2

Answers


  1. Chosen as BEST ANSWER

    Clearing cache and restarting horizon worked.

    php artisan optimize:clear


  2. Did you check the queue worker running?
    I think it’s not, please check if.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search