url = env('SD_INGEST_URL') . '/ingest'; } public function execute($id, $document) { try { $response = $this->sendRequest($id, $document); if ($response['status'] === 'fail') { $message = array_key_exists('message', $response) ? $response['message'] : 'Something went wrong.'; throw new \Exception($message); } // The file in Ingest si in Processing state. } catch (\Exception $exception) { throw new \Exception($exception->getMessage()); } } public function sendRequest($id, $document) { $client = new Client(); $response = $client->request('post', $this->url, [ 'headers' => [ 'Accept' => 'application/json', ], 'multipart' => [ [ 'name' => 'id', 'contents' => $id, ], [ 'name' => 'document', 'contents' => fopen($document['path'], 'r'), 'filename' => $document['name'], 'Content-type' => $document['type'], ] ], ]); return json_decode($response->getBody()->getContents(), true); } }