我有两个文件userPolicy.php
,userObserver.php
我在两个文件中都写了一些逻辑,如果用户有任何活动订阅,用户不会被删除,这意味着它工作正常。
userPolicy.php
public function delete(User $user, $item)
{
$canceled_subscription=new userObserver();
return (!$canceled_subscription->deleting($item)) && ($user->hasAdminRole());
}
userObserver.php
public function deleting(Plan $item){
//based on $has_subscriptions it should allow to delete or call the userPolicy.php delete function
$has_subscriptions=$item->subscriptions()->where('status','!=','canceled')->exists();
return $has_subscriptions;
}
现在我想要的是我想重构来自 userPolicy.php 的代码,这意味着有没有办法减少来自 userPolicy.php 文件的代码(主要是 $canceled_subscriptions),有没有机会减少来自 userPolicy 的代码。 php请帮我重构代码