/** * Returns a new form of the specified work order report. * * @param WorkOrder $workOrder * @param WorkOrderReport $report * * @return \Orchestra\Contracts\Html\Builder */ public function form(WorkOrder $workOrder, WorkOrderReport $report) { return $this->form->of('work-orders.report', function (FormGrid $form) use($workOrder, $report) { if ($report->exists) { $method = 'PATCH'; $url = route('maintenance.work-orders.report.update', [$workOrder->getKey(), $report->getKey()]); $form->submit = 'Save'; } else { $method = 'POST'; $url = route('maintenance.work-orders.report.store', [$workOrder->getKey()]); $form->submit = 'Create'; } $form->attributes(compact('method', 'url')); $form->with($report); $form->fieldset(function (Fieldset $fieldset) use($workOrder) { $fieldset->control('select', 'status')->options(function () { $statuses = Status::all()->pluck('name', 'id'); $statuses[0] = 'None'; return $statuses; })->value(function () use($workOrder) { if ($workOrder->status instanceof Status) { return $workOrder->status->getKey(); } })->attributes(['class' => 'select2']); $fieldset->control('input:textarea', 'description'); }); }); }
/** * Execute the job. * * @return bool */ public function handle() { $this->report->user_id = auth()->id(); $this->report->work_order_id = $this->workOrder->getKey(); $this->report->description = $this->request->clean($this->request->input('description')); if ($this->report->save()) { $this->workOrder->complete($this->request->input('status')); return true; } return false; }
/** * Creates a new work order report. * * @param ReportRequest $request * @param int|string $workOrderId * * @return bool */ public function store(ReportRequest $request, $workOrderId) { $workOrder = $this->workOrder->findOrFail($workOrderId); $report = $this->report->newInstance(); return $this->dispatch(new Store($request, $workOrder, $report)); }