url = env('WEBHOOK_CORE_URL') . '/webhooks'; $this->secret = env('WEBHOOK_CORE_SECRET'); $this->filePath = $filePath; $string = str_replace('contracts/', '', $this->filePath); $result = explode('.', $string); $this->id = $result[0]; } /** * Execute the job. * * @return void */ public function handle() { $content = ''; // File exists, send content. if ($this->filePath) { $this->storage = Storage::disk('local'); // @TODO Check if the file exists multiple times? if ( ! $this->storage->exists($this->filePath)) { throw new \Exception('File does not exist yet.'); } $content = $this->storage->get($this->filePath); } $sent = $this->sendTheData($content); // if ($this->filePath && $sent) { if ($this->filePath) { $this->storage->delete($this->filePath); } } public function failed() { if ($this->filePath) { $this->storage->delete($this->filePath); } } /** * Send the data to the core trough webhooks * * @param $content * @param string $status */ private function sendTheData($content) { try { WebhookCall::create() ->url($this->url) ->payload(['data' => [ 'id' => $this->id, 'content' => $content, 'status' => $content ? 'success' : 'fail', ]]) ->useSecret($this->secret) ->dispatch(); return true; } catch (\Exception $exception) { Log::error('SendToCore@sendTheData' . $exception->getMessage()); return false; } } }