将数据传递到队列作业会产生404-不是其他错误



来自我的控制器

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

MonthlyReport.php

use AppReport;
private $rep;
public function __construct(Report $report)
{
$this->rep = $report;
}
public function handle()
{
dd($this->rep);
}

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

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

我的Web.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>

如果您只想检查作业句柄中的$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);
}

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

最新更新