0

我有这种情况,我会在一个页面中有多个发布请求。用户应该搜索词缀(前缀、中缀、后缀),所以我为每个词缀制作了 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 的新手,所以我可能在理解某些方面有困难,但我很想学习它!我希望我能找到答案。

4

1 回答 1

2

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

于 2017-09-25T14:16:39.790 回答