改进 删除逻辑

This commit is contained in:
iVampireSP.com 2022-11-08 17:46:05 +08:00
parent ec99867379
commit c27ed95ace
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -38,9 +38,6 @@ public function handle()
{ {
// //
// dd($this->host);
// $host = HostModel::find($this->host);
$host = $this->host; $host = $this->host;
$host->load(['module']); $host->load(['module']);
@ -49,39 +46,24 @@ public function handle()
switch ($this->type) { switch ($this->type) {
case 'patch': case 'patch':
$response = $http->patch('hosts/' . $host->id, $host->toArray()); $response = $http->patch('hosts/' . $host->id, $host->toArray());
break; break;
case 'post': case 'post':
$response = $http->post('hosts', $host->toArray()); $response = $http->post('hosts', $host->toArray());
break; break;
case 'delete': case 'delete':
$response = $http->delete('hosts/' . $host->id); $response = $http->delete('hosts/' . $host->id);
// if successful // if successful
if ($response->successful()) { if ($response->successful() || $response->status() === 404) {
$host->delete(); $host->delete();
} }
if ($response->status() === 404) {
$host->delete();
}
return 0;
// if response code is 404
// if ($response->successful() || $response->failed()) {
// $host->delete();
// }
// if success
// if ($response->successful()) {
// $host->delete();
// }
break; break;
} }
if ($this->type !== 'delete') {
if (!$response->successful()) { if (!$response->successful()) {
$host->status = 'error'; $host->status = 'error';
} }
@ -89,3 +71,4 @@ public function handle()
$host->save(); $host->save();
} }
} }
}