改进 删除逻辑

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->load(['module']);
@ -49,43 +46,29 @@ public function handle()
switch ($this->type) {
case 'patch':
$response = $http->patch('hosts/' . $host->id, $host->toArray());
break;
case 'post':
$response = $http->post('hosts', $host->toArray());
break;
case 'delete':
$response = $http->delete('hosts/' . $host->id);
// if successful
if ($response->successful()) {
if ($response->successful() || $response->status() === 404) {
$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;
}
if (!$response->successful()) {
$host->status = 'error';
}
if ($this->type !== 'delete') {
if (!$response->successful()) {
$host->status = 'error';
}
$host->save();
$host->save();
}
}
}