Changeset View
Changeset View
Standalone View
Standalone View
src/app/Group.php
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
protected $fillable = [ | protected $fillable = [ | ||||
'email', | 'email', | ||||
'members', | 'members', | ||||
'name', | 'name', | ||||
'status', | 'status', | ||||
]; | ]; | ||||
/** | |||||
* Assign the group to a wallet. | |||||
* | |||||
* @param \App\Wallet $wallet The wallet | |||||
* | |||||
* @return \App\Group Self | |||||
* @throws \Exception | |||||
*/ | |||||
public function assignToWallet(Wallet $wallet): Group | |||||
{ | |||||
if (empty($this->id)) { | |||||
throw new \Exception("Group not yet exists"); | |||||
} | |||||
if ($this->entitlements()->count()) { | |||||
throw new \Exception("Group already assigned to a wallet"); | |||||
} | |||||
$sku = \App\Sku::withObjectTenantContext($this)->where('title', 'group')->first(); | |||||
$exists = $wallet->entitlements()->where('sku_id', $sku->id)->count(); | |||||
\App\Entitlement::create([ | |||||
'wallet_id' => $wallet->id, | |||||
'sku_id' => $sku->id, | |||||
'cost' => $exists >= $sku->units_free ? $sku->cost : 0, | |||||
'fee' => $exists >= $sku->units_free ? $sku->fee : 0, | |||||
'entitleable_id' => $this->id, | |||||
'entitleable_type' => Group::class | |||||
]); | |||||
return $this; | |||||
} | |||||
/** | /** | ||||
* Returns group domain. | * Returns group domain. | ||||
* | * | ||||
* @return ?\App\Domain The domain group belongs to, NULL if it does not exist | * @return ?\App\Domain The domain group belongs to, NULL if it does not exist | ||||
*/ | */ | ||||
public function domain(): ?Domain | public function domain(): ?Domain | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |