修复 删除主机时候的问题

This commit is contained in:
iVampireSP.com 2022-11-27 21:04:20 +08:00
parent 7f82471dc4
commit c772ed4bbf
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 14 additions and 3 deletions

View File

@ -42,8 +42,10 @@ public function update(HostRequest $request, Host $host): JsonResponse
return $this->updated($host);
}
public function destroy(HostRequest $host)
public function destroy(HostRequest $request, Host $host): JsonResponse
{
unset($request);
if ($host->status == 'pending') {
// 如果上次更新时间大于 5min
if (time() - strtotime($host->updated_at) > 300) {

View File

@ -2,6 +2,7 @@
namespace App\Http\Requests\User;
use App\Models\Host;
use Illuminate\Foundation\Http\FormRequest;
class HostRequest extends FormRequest
@ -15,8 +16,16 @@ public function authorize(): bool
{
$host = $this->route('host');
// 检测是否是自己的主机
return $host->user_id == auth()->id();
if (!($host instanceof Host)) {
$host = Host::where('id', $host)->first();
}
if ($host->user_id ?? 0 == $this->user()->id) {
return true;
} else {
return false;
}
}
/**