Changeset View
Changeset View
Standalone View
Standalone View
src/app/Traits/EntitleableTrait.php
Show First 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | public function wallet(): ?Wallet | ||||
// TODO: No entitlement should not happen, but in tests we have | // TODO: No entitlement should not happen, but in tests we have | ||||
// such cases, so we fallback to the user's wallet in this case | // such cases, so we fallback to the user's wallet in this case | ||||
if ($this instanceof \App\User) { | if ($this instanceof \App\User) { | ||||
return $this->wallets()->first(); | return $this->wallets()->first(); | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
/** | |||||
* Return the owner of the wallet (account) this entitleable is assigned to | |||||
* | |||||
* @return ?\App\User Account owner | |||||
*/ | |||||
public function walletOwner(): ?\App\User | |||||
{ | |||||
$wallet = $this->wallet(); | |||||
if ($wallet) { | |||||
if ($this instanceof \App\User && $wallet->user_id == $this->id) { | |||||
return $this; | |||||
} | |||||
return $wallet->owner; | |||||
} | |||||
return null; | |||||
} | |||||
} | } |