关闭'关闭的异常序列化在Queue.php中不允许(第127行)

时间:2017-09-01 16:53:27

标签: php laravel laravel-5 laravel-5.4 laravel-jobs

我遇到这种情况,我会在一个页面中有多个帖子请求。用户应该搜索词缀(前缀,中缀,后缀),因此我为每个词组制作了3个搜索栏。我终于(?)找到了问题的解决方案,但又出现了另一个问题,我不知道是什么导致了这个问题。

我收到此错误:

(1/1) Exception
   Serialization of 'Closure' is not allowed
   in Queue.php (line 127)
   at serialize(object(getPSearch))
   in Queue.php (line 127)
   at Queue->createObjectPayload(object(getPSearch))
   in Queue.php (line 108)
   at Queue->createPayloadArray(object(getPSearch), '', null)
   in Queue.php (line 86)
   at Queue->createPayload(object(getPSearch), '', null)
   in SyncQueue.php (line 37)
   at SyncQueue->push(object(getPSearch))
   in Dispatcher.php (line 184)
   at Dispatcher->pushCommandToQueue(object(SyncQueue), object(getPSearch))
   in Dispatcher.php (line 159)
   at Dispatcher->dispatchToQueue(object(getPSearch))
   in Dispatcher.php (line 73)
   at Dispatcher->dispatch(object(getPSearch))
   in DispatchesJobs.php (line 17)
   at Controller->dispatch(object(getPSearch))
   in HomeController.php (line 42)
   at HomeController->findAction(object(Request))

我的HomeController,findAction函数:

public function findAction(Request $request){
        if ($request->has('psearch')) {
            return $this->dispatch(new \App\Jobs\getPSearch($request));
        } elseif ($request->has('isearch')) {
            return $this->dispatch(new \App\Jobs\getISearch($request));
        } elseif ($request->has('ssearch')) {
            return $this->dispatch(new \App\Jobs\getSSearch($request));
        }
        return 'no action found';
    }

我的getPSearch,getISearch,getSSearch作业(它们有一些相同的功能但是变量不同):

protected $data;
public function __construct($data)
{
    $this->data = $data;
}

public function handle()
{
    $data = $this->data;
    $prefixes = DB::table('circumfixes')->select('*')->distinct()->where('prefix', '=', $data.'-')->get();
    $infixes=DB::table('infixes')->select('*')->distinct()->get();
    $suffixes=DB::table('suffixes')->select('*')->distinct()->get();

    $affixes=[
        'prefixes' => $prefixes,
        'infixes' => $infixes,
        'suffixes' => $suffixes
    ];
    return view('home', $affixes);
}

我的路线:

Route::get('/home', 'HomeController@index')->name('home');
Route::post('/home', 'HomeController@findAction');

我试图搜索如何在线解决问题,但我似乎无法找到一个我能理解的解决方案。我是Laravel的新手,所以我可能很难理解一些要点,但我很想学习它!我希望我能找到答案。

1 个答案:

答案 0 :(得分:2)

而不是$ request ...传递$ request-> all()作为Jobs构造函数的参数