首页 > 解决方案 > 将数据传递给队列作业给出 404 - 不是其他错误

问题描述

从我的控制器

use App\Jobs\MonthlyReport;

public function store(Request $request)
{
  $report = new Report;
  ...
  $report->save();
  $this->dispatch(new MonthlyReport($report));
  return $report;
}

月报.php

use App\Report;

private $rep;

public function __construct(Report $report)
{
    $this->rep = $report;
}

public function handle()
{
    dd($this->rep);
}

它给出404,没有其他错误。但是如果我没有传递$report变量,那么它就可以工作。触发404而不是错误的问题应该是什么?dd();

注意:在另一个项目中使用相同的逻辑并且它正在工作,但不是在这里

我的网页.php

Route::resource('report', 'ReportController');

我的表单(年月数据来自 JQuery)

<form method="POST" action="/report">
@csrf
<div class="form-group">
    <label class="required">Office</label>
    <select class="form-control" id="change_office" required name="office">
        <option value>choose office</option>
        @foreach ($offices as $office)
            <option value="{{ $office->id }}">{{ $office->name }}</option>
        @endforeach
    </select>
</div>

<div class="form-group">
    <label class="required" for="year">Option</label>
    <select id="option" class="form-control" name="option" required>
        <option value="">Choose options</option>
        <option value="Monthly">Monthly</option>
        <option value="Quarterly">Quarterly</option>
        <option value="Yearly">Yearly</option>
        <option value="Custom">Custom</option>
        <option value="Time Base">Entry/Exit Report</option>
    </select>
</div>

<div class="form-group" id="yearly_wrapper" style="display: none;">
    <label class="required" for="year">Year</label>
    <select id="year" class="form-control" name="year">
        <option value="">Choose year</option>
    </select>
</div>

<div class="form-group" id="monthly_wrapper" style="display: none;">
    <label class="required">Select Month</label>
    <select id="monthly" class="form-control" name="monthly">
        <option value="">Select month</option>
    </select>
</div>

<div>
    <button type="submit" class="btn btn-outline-warning btn-round">
        <i class="now-ui-icons ui-1_check"></i> Generate
    </button>
</div>
</form>

标签: phplaravellaravel-jobs

解决方案


如果您只想检查$report您的工作句柄,请尝试以下操作:

工作类

public function handle()
{
    Log::info('Report created', $this->rep);
    return;
}

控制器

public function store(Request $request)
{
  $report = new Report;
  ...
  $report->save();

  return MonthlyReport::dispatch($report);
}

如果一切正常,您应该会在日志文件中看到创建的报告。


推荐阅读