gpt4 book ai didi

php - 作业类不接受从 laravel 中的 Controller 发送的参数

转载 作者:可可西里 更新时间:2023-11-01 00:58:21 24 4
gpt4 key购买 nike

错误:显示 App\Jobs\ReorderDatabase::handle() 缺少参数 1, 我需要从 Controller 传递变量,我不需要使用模型, 所以我应该如何进行。

我的 Controller 功能代码在这里

    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++;
}
}
}

最佳答案

正如@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++;
}
}
}

关于php - 作业类不接受从 laravel 中的 Controller 发送的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34690498/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com