php - Passing data to Queue Job gives 404 - Not other Error
Get the solution ↓↓↓
From My Controller
use App\Jobs\MonthlyReport;
public function store(Request $request)
{
$report = new Report;
...
$report->save();
$this->dispatch(new MonthlyReport($report));
return $report;
}
MonthlyReport.php
use App\Report;
private $rep;
public function __construct(Report $report)
{
$this->rep = $report;
}
public function handle()
{
dd($this->rep);
}
It gives 404, no other error. But If I didn't pass$report variable then it's working. What should be the problem that trigger 404 instead of error ordd();
Note: The same logic is used in another project and it's working, but not here
My Web.php
Route::resource('report', 'ReportController');
My Form (Year and month data are coming from 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>
Answer
Solution:
If you just want to check the$report in your job handle, try something like this:
Job Class
public function handle()
{
Log::info('Report created', $this->rep);
return;
}
Controller
public function store(Request $request)
{
$report = new Report;
...
$report->save();
return MonthlyReport::dispatch($report);
}
If everything is ok, you should see the created report in your log file.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: to enable extensions, verify that they are enabled in your .ini files
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

