修复 删除主机时候的问题
This commit is contained in:
parent
7f82471dc4
commit
c772ed4bbf
@ -42,8 +42,10 @@ public function update(HostRequest $request, Host $host): JsonResponse
|
|||||||
return $this->updated($host);
|
return $this->updated($host);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(HostRequest $host)
|
public function destroy(HostRequest $request, Host $host): JsonResponse
|
||||||
{
|
{
|
||||||
|
unset($request);
|
||||||
|
|
||||||
if ($host->status == 'pending') {
|
if ($host->status == 'pending') {
|
||||||
// 如果上次更新时间大于 5min
|
// 如果上次更新时间大于 5min
|
||||||
if (time() - strtotime($host->updated_at) > 300) {
|
if (time() - strtotime($host->updated_at) > 300) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests\User;
|
namespace App\Http\Requests\User;
|
||||||
|
|
||||||
|
use App\Models\Host;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
class HostRequest extends FormRequest
|
class HostRequest extends FormRequest
|
||||||
@ -15,8 +16,16 @@ public function authorize(): bool
|
|||||||
{
|
{
|
||||||
$host = $this->route('host');
|
$host = $this->route('host');
|
||||||
|
|
||||||
// 检测是否是自己的主机
|
if (!($host instanceof Host)) {
|
||||||
return $host->user_id == auth()->id();
|
$host = Host::where('id', $host)->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($host->user_id ?? 0 == $this->user()->id) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user