错误:显示App \ Jobs \ ReorderDatabase :: handle()缺少参数1, 我需要从控制器传递变量,我不需要使用模型, 那我该怎么办呢。
我的控制器功能代码在这里
public function postData(Request $request)
{
$updateRecordsArray = Input::get('order');
$this->dispatch(new ReorderDatabase($updateRecordsArray));
return Response::json('Okay');
}
我的作业RecorderDatabase工作代码是
<?php namespace App\Jobs;
use App\Http\Requests\Request;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\DragDropController;
/**
* Class ReorderDatabase
* @package App\Jobs
*/
class ReorderDatabase extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Execute the job.
*
* @return void
*/
public function handle($updateRecordsArray)
{
$i = 1;
foreach ($updateRecordsArray as $recordID) {
DB::table('venues')->where('id', '=', $recordID)->update(array('priority' => $i));
$i++;
}
}
}
答案 0 :(得分:4)
正如@lagbox所提到的,你需要将这个参数传递给构造函数而不是handle
方法。
你的工作班应该是这样的:
<?php namespace App\Jobs;
use App\Http\Requests\Request;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\DragDropController;
/**
* Class ReorderDatabase
* @package App\Jobs
*/
class ReorderDatabase extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
protected $updateRecordsArray;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($updateRecordsArray)
{
$this->updateRecordsArray = $updateRecordsArray;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$i = 1;
foreach ($this->updateRecordsArray as $recordID) {
DB::table('venues')->where('id', '=', $recordID)->update(array('priority' => $i));
$i++;
}
}
}