I have two files userPolicy.php
and userObserver.php
, i write some logic inside both files what it does means if a user have any active subscriptions that user won't be deleted upto this it's working fine .
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;
}
Now what i want is i want to refactor the code from the the userPolicy.php that means is there any way to reduce the code from the userPolicy.php file (mainly $canceled_subscriptions),is there any chance to reduce the code from userPolicy.php please help me to refactor the code