event_id = $event_id; $this->entity = $entity; } /** * Execute the job. * * @return void */ public function handle() :bool { if(!$this->entity->company || $this->entity->company->company_users->first()->is_migrating) return true; //info("i got past the check"); $subscriptions = Subscription::where('company_id', $this->entity->company_id) ->where('event_id', $this->event_id) ->get(); if(!$subscriptions || $subscriptions->count() == 0) return true; $subscriptions->each(function($subscription) { $this->process($subscription); }); return true; } private function process($subscription) { // generate JSON data $manager = new Manager(); $manager->setSerializer(new ArraySerializer()); $manager->parseIncludes($include); $transformer = new $this->getTransformerClassName(); $resource = new Item($this->entity, $transformer, $this->entity->getEntityType()); $data = $manager->createData($resource)->toArray(); $this->postData($subscription, $data, []); } private function getTransformerClassName() { return sprintf('App\\Transformers\\%sTransformer', class_basename($this->entity)); } private function postData($subscription, $data, $headers = []) { $base_headers = [ 'Content-Length' => strlen($data), 'Accept' => 'application/json' ]; $client = new \GuzzleHttp\Client(['headers' => array_merge($base_headers, $headers)]); //$response = $client->request('POST', $subscription->target_url, ['form_params' => $data]); $response = $client->post($subscription->target_url, [ GuzzleHttp\RequestOptions::JSON => $data // or 'json' => [...] ]); if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200) { $subscription->delete(); } } public function failed($exception) { $exception->getMessage(); // etc... } }