authorize('jobs.manage'); if ($job === null) { $this->form->responsible_user_id = (string) auth()->id(); return; } $details = $jobQueries->findDetails($job); abort_if($details === null, 404); $this->jobId = $details->id; $this->jobNumber = $details->number; $this->customerName = $details->customer->name; $this->storedStatus = $details->status->value; $this->form->fillFromDetails($details); } public function save(CreateCustomerJob $createJob, UpdateCustomerJob $updateJob, CustomerJobQueries $jobQueries): void { $this->authorize('jobs.manage'); $status = JobStatus::tryFrom($this->form->status); if ($status !== null && $status->value !== $this->storedStatus && ! $this->maySetStatus($status)) { $this->addError('form.status', __('jobs.errors.status_not_allowed')); return; } $data = $this->form->toData(); try { if ($this->jobId === null) { $jobId = $createJob->execute($data, (int) auth()->id()); $number = $jobQueries->findDetails($jobId)->number ?? ''; session()->flash('status', __('jobs.created', ['number' => $number, 'name' => trim($data->name)])); } else { $updateJob->execute($this->jobId, $data, (int) auth()->id()); $jobId = $this->jobId; session()->flash('status', __('jobs.updated', ['number' => $this->jobNumber])); } } catch (CustomerJobNotFound) { abort(404); } catch (DomainException $exception) { $this->form->showDomainError($exception); return; } $this->redirectRoute('jobs.show', $jobId, navigate: true); } public function heading(): string { return $this->jobId === null ? __('jobs.create_title') : __('jobs.edit_title').' '.$this->jobNumber; } public function render(): mixed { return $this->view()->title($this->heading()); } }; ?> @php $userOptions = collect($this->users)->map(fn ($user) => [ 'value' => $user->id, 'label' => $user->name, 'note' => $user->role === Role::Subcontractor ? __('users.roles.subcontractor') : null, ])->all(); $staffOptions = collect($this->users)->reject(fn ($user) => $user->role === Role::Subcontractor); @endphp
{{ $statusMessage }}