id = $payload['data']['id']; $this->content = $payload['data']['content']; $this->status = $payload['data']['status']; } public function handle() { $storage = Storage::disk('local'); $fileName = 'document'; // The .md extension signals the success status, the lack of signals the fail status. if ($this->status === 'success') { $fileName = $fileName . '.md'; } $dir = "contracts/$this->id"; try { $storage->makeDirectory($dir); $storage->put("$dir/$fileName", $this->content['document']); foreach ($this->content['images'] as $image) { $name = $image['name']; $type = $image['type']; $contents = $image['contents']; $contents = str_replace('data:image/' . $type . ';base64,', '', $contents); $storage->put("$dir/$name.$type", base64_decode($contents)); } IngestDocumentReceived::dispatch($this->id); } catch (\Exception $exception) { \Illuminate\Support\Facades\Log::info('Exception: ' . $exception->getTraceAsString()); } } }