Laravel |队列失败:缺少App \ Jobs \ SendCollectionSMS的参数1:

时间:2017-05-10 08:52:36

标签: php laravel parameters constructor laravel-5.4

由于这个奇怪的错误,我的所有工作都失败了,并且无法弄清楚这里的问题是什么。

作业

{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
 * Create a new job instance.
 *
 * @return void
 */
public $fName, $lName, $colAmt, $colDate, $totalAmt, $balAmt, $dueDate, $mobile_no, $is_loan_complete;

public function __construct($fName, $lName, $colAmt, $colDate, $totalAmt, $balAmt, $dueDate, $mobile_no, $is_loan_complete)
{
    //
    $this->fName = $fName;
    $this->lName = $lName;
    $this->colAmt = $colAmt;
    $this->colDate = $colDate;
    $this->totalAmt = $totalAmt;
    $this->balAmt = $balAmt;
    $this->dueDate = $dueDate;
    $this->mobile_no = $mobile_no;
    $this->is_loan_complete = $is_loan_complete;
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle($fName, $lName, $colAmt, $colDate, $totalAmt, $balAmt, $dueDate, $mobile_no, $is_loan_complete)
{
    //

            $username = "xxxxxxxxxx";
        $hash = "xxxxxxxxxxxxxxxxxxxxxxxxx";

        // Config variables. Consult http://api.textlocal.in/docs for more info.
        $test = "0";

        // Data for text message. This is the text message data.
        $sender = "xxxxx"; // This is who the message appears to be from.
        $numbers = $mobile_no; // A single number or a comma-seperated list of numbers

        $message = "Dear ".$fName." ".$lName.", your payment of Rs. ".$colAmt." has been received on ".$colDate.".
    Total: Rs. ".$totalAmt.", Balance: ".$balAmt.", Due Date: ".$dueDate.". Thank You";
        // 612 chars or less
        // A single number or a comma-seperated list of numbers
        $message = urlencode($message);

        $data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
        $ch = curl_init('http://api.textlocal.in/send/?');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        echo $result = curl_exec($ch); // This is the result from the API
        curl_close($ch);
        $this->pusher($result); 


}

从我的failed_jobs表中的错误我发现由于参数错误,句柄函数甚至没有运行

抛出异常:

exception 'ErrorException' with message 'Missing argument 1 for App\Jobs\SendCollectionSMS::handle()' in C:\xampp\htdocs\financetest1\app\Jobs\SendCollectionSMS.php:42
Stack trace:
#0 C:\xampp\htdocs\financetest1\app\Jobs\SendCollectionSMS.php(42): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Missing argumen...', 'C:\\xampp\\htdocs...', 42, Array)
#1 [internal function]: App\Jobs\SendCollectionSMS->handle()
#2 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(30): call_user_func_array(Array, Array)
#3 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#4 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#5 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Container\Container.php(531): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#6 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#7 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(114): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\SendCollectionSMS))
#8 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\SendCollectionSMS))
#9 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#10 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(43): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\SendCollectionSMS), NULL)
#11 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(69): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#12 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(291): Illuminate\Queue\Jobs\Job->fire()
#13 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(258): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#14 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(110): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#15 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(101): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#16 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(85): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#17 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#18 C:\xampp\htdocs\financetest1\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(30): call_user_func_array(Array, Array)

我从控制器调用这个工作,如:(对不起下面的代码中的混乱,但它有效)

dispatch(new SendCollectionSMS(ucwords($collection->loan->customer->first_name), ucwords($collection->loan->customer->last_name), $collection->collected_amount, Carbon::parse($collection->created_at)->format('d-m-Y'), $collection->loan->loan_amount, ($collection->loan->loan_amount - $collection->loan->collected_amount), Carbon::parse($collection->loan->end_date)->format('d-m-Y'), $collection->loan->customer->mobile_no, false));

现在我很肯定我在控制器中创建新作业时所传递的参数是正确的但似乎我在处理程序中引用变量的方式存在问题。

这里出了什么问题?

1 个答案:

答案 0 :(得分:1)

这是一篇非常古老的帖子,但是遇到了这个问题的任何人。

您的句柄功能不需要任何变量

public function handle()

在此函数中,您可以通过调用它们来获取变量:

$this->fName

如果您仍然遇到错误的参数1"问题:重新启动工匠命令

php artisan queue:work

我花了一些时间才弄清楚,如果你的队列:工作已经在运行,更改你的工作文件没有任何效果。

相关问题