host = $host; $this->type = $type; } /** * Execute the job. * * @return void */ public function handle() { // $this->host->load(['module']); $http = Http::remote($this->host->module->api_token, $this->host->module->url); switch ($this->type) { case 'patch': $response = $http->patch('hosts/' . $this->host->id, $this->host->toArray()); break; case 'post': $response = $http->post('hosts', $this->host->toArray()); break; case 'delete': $response = $http->delete('hosts/' . $this->host->id); // if success if ($response->successful()) { $this->host->delete(); } break; } if (!$response->successful()) { $this->host->status = 'error'; } $this->host->save(); } }