Passing data to Queue Job gives 404 - Not other Error

368 views Asked by At

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 or dd();

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>
1

There are 1 answers

2
P. K. Tharindu On

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.