completion->update([ 'status' => AiFormCompletion::STATUS_PROCESSING, ]); try { // Use the static run method to execute the prompt $formData = GenerateFormPrompt::run($this->completion->form_prompt); $this->completion->update([ 'status' => AiFormCompletion::STATUS_COMPLETED, 'result' => $formData ]); } catch (\Exception $e) { $this->onError($e); } } /** * Handle a job failure. */ public function failed(\Throwable $exception): void { $this->onError($exception); } private function onError(\Throwable $e) { $this->completion->update([ 'status' => AiFormCompletion::STATUS_FAILED, 'error' => $e->getMessage(), ]); } }