php Laravel脚本试图在不完整的对象上调用方法

vsdwdz23  于 2023-06-28  发布在  PHP
关注(0)|答案(3)|浏览(84)

我刚刚从v8升级到Laravel 9,突然我开始得到这个错误,

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

错误来自下面的文件,第33行是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();
            });
        }
    }
}

你觉得我做错了什么?
Laravel版本:9.11.0 PHP版本:8.0.18

9avjhtql

9avjhtql1#

你检查了正在运行的队列worker吗?我想不是,请检查一下。

gcxthw6b

gcxthw6b2#

清除缓存并重新启动地平线工作。
php artisan optimize:clear

6kkfgxo0

6kkfgxo03#

请按照这个问题的答案-这是相当翔实的我。访问https://stackoverflow.com/a/42086014/6517636

相关问题