Home > other >  Laravel the script tried to call a method on an incomplete object
Laravel the script tried to call a method on an incomplete object

Time:07-06

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 "Laravel\SerializableClosure\SerializableClosure" 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): Illuminate\Queue\CallQueuedClosure::handle
#34 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}
#33 /vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\Util::unwrapIfClosure
#32 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\BoundMethod::callBoundMethod
#31 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::call
#30 /vendor/laravel/framework/src/Illuminate/Container/Container.php(610): Illuminate\Container\Container::call
#29 /vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\Bus\Dispatcher::Illuminate\Bus\{closure}
#28 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#27 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline::then
#26 /vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\Bus\Dispatcher::dispatchNow
#25 /vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(118): Illuminate\Queue\CallQueuedHandler::Illuminate\Queue\{closure}
#24 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#23 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline::then
#22 /vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(120): Illuminate\Queue\CallQueuedHandler::dispatchThroughMiddleware
#21 /vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): Illuminate\Queue\CallQueuedHandler::call
#20 /vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\Jobs\Job::fire
#19 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(406): Illuminate\Queue\Worker::process
#18 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(356): Illuminate\Queue\Worker::runJob
#17 /vendor/laravel/framework/src/Illuminate/Queue/Worker.php(158): Illuminate\Queue\Worker::daemon
#16 /vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(116): Illuminate\Queue\Console\WorkCommand::runWorker
#15 /vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(100): Illuminate\Queue\Console\WorkCommand::handle
#14 /vendor/laravel/horizon/src/Console/WorkCommand.php(51): Laravel\Horizon\Console\WorkCommand::handle
#13 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}
#12 /vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\Util::unwrapIfClosure
#11 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\BoundMethod::callBoundMethod
#10 /vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::call
#9 /vendor/laravel/framework/src/Illuminate/Container/Container.php(610): Illuminate\Container\Container::call
#8 /vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Console\Command::execute
#7 /vendor/symfony/console/Command/Command.php(298): Symfony\Component\Console\Command\Command::run
#6 /vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Illuminate\Console\Command::run
#5 /vendor/symfony/console/Application.php(1015): Symfony\Component\Console\Application::doRunCommand
#4 /vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application::doRun
#3 /vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application::run
#2 /vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Illuminate\Console\Application::run
#1 /vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Foundation\Console\Kernel::handle
#0 /artisan(37): null

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

<?php

namespace App\Logging;

use App\Models\HttpLog;
use Illuminate\Http\Request;

class CustomLogWriter implements \Spatie\HttpLogger\LogWriter
{
    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

CodePudding user response:

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

CodePudding user response:

Clearing cache and restarting horizon worked.

php artisan optimize:clear

  • Related