Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/WalletObserver.php
<?php | <?php | ||||
namespace App\Observers; | namespace App\Observers; | ||||
use App\User; | |||||
use App\Wallet; | use App\Wallet; | ||||
/** | /** | ||||
* This is an observer for the Wallet model definition. | * This is an observer for the Wallet model definition. | ||||
*/ | */ | ||||
class WalletObserver | class WalletObserver | ||||
{ | { | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | public function updated(Wallet $wallet) | ||||
if ( | if ( | ||||
method_exists($entitlement->entitleable_type, 'unsuspend') | method_exists($entitlement->entitleable_type, 'unsuspend') | ||||
&& !empty($entitlement->entitleable) | && !empty($entitlement->entitleable) | ||||
) { | ) { | ||||
$entitlement->entitleable->unsuspend(); | $entitlement->entitleable->unsuspend(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Remove RESTRICTED flag from the wallet owner and all users in the wallet | |||||
if ($wallet->balance > $wallet->getOriginal('balance') && $wallet->owner && $wallet->owner->isRestricted()) { | |||||
\Log::info('>>>>>>>>>>'); | |||||
User::whereIn('id', $wallet->entitlements()->select('entitleable_id')->where('entitleable_type', User::class)) | |||||
->each(function ($user) { | |||||
$user->unrestrict(); | |||||
}); | |||||
$wallet->owner->unrestrict(); | |||||
} | |||||
} | } | ||||
} | } |