改进 推介计划删除与权限判断
This commit is contained in:
parent
22e7016f1f
commit
8453014ac7
@ -92,14 +92,6 @@ public function show($affiliate): RedirectResponse
|
|||||||
*/
|
*/
|
||||||
public function destroy(Affiliates $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();
|
$affiliate->delete();
|
||||||
|
|
||||||
return redirect()->route('affiliates.create')->with('success', '推介计划已经成功删除。');
|
return redirect()->route('affiliates.create')->with('success', '推介计划已经成功删除。');
|
||||||
|
@ -31,6 +31,11 @@ public static function booted()
|
|||||||
static::creating(function (self $affiliate) {
|
static::creating(function (self $affiliate) {
|
||||||
$affiliate->uuid = Str::ulid();
|
$affiliate->uuid = Str::ulid();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static::deleting(function (self $affiliate) {
|
||||||
|
$affiliate->users()->delete();
|
||||||
|
$affiliate->user->update(['affiliate_id' => null]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeThisUser(Builder $query): Builder
|
public function scopeThisUser(Builder $query): Builder
|
||||||
|
Loading…
Reference in New Issue
Block a user