From 8453014ac770ef2a51a767b579d73c981965482a Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Tue, 28 Feb 2023 20:34:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20=E6=8E=A8=E4=BB=8B?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E5=88=A0=E9=99=A4=E4=B8=8E=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Web/AffiliateController.php | 8 -------- app/Models/Affiliate/Affiliates.php | 5 +++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Web/AffiliateController.php b/app/Http/Controllers/Web/AffiliateController.php index 6d57322..ef4a34c 100644 --- a/app/Http/Controllers/Web/AffiliateController.php +++ b/app/Http/Controllers/Web/AffiliateController.php @@ -92,14 +92,6 @@ public function show($affiliate): RedirectResponse */ public function destroy(Affiliates $affiliate): RedirectResponse { - // 检测是不是自己的推介计划 - if ($affiliate->user_id !== auth()->id()) { - return redirect()->route('affiliates.index')->with('error', '您没有权限删除此推介计划。'); - } - - AffiliateUser::where('affiliate_id', $affiliate->id)->delete(); - User::where('affiliate_id', $affiliate->id)->update(['affiliate_id' => null]); - $affiliate->delete(); return redirect()->route('affiliates.create')->with('success', '推介计划已经成功删除。'); diff --git a/app/Models/Affiliate/Affiliates.php b/app/Models/Affiliate/Affiliates.php index 18e2b23..b5c157d 100644 --- a/app/Models/Affiliate/Affiliates.php +++ b/app/Models/Affiliate/Affiliates.php @@ -31,6 +31,11 @@ public static function booted() static::creating(function (self $affiliate) { $affiliate->uuid = Str::ulid(); }); + + static::deleting(function (self $affiliate) { + $affiliate->users()->delete(); + $affiliate->user->update(['affiliate_id' => null]); + }); } public function scopeThisUser(Builder $query): Builder