Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
Show First 20 Lines • Show All 493 Lines • ▼ Show 20 Lines | public function unsuspend(): void | ||||
$this->status ^= User::STATUS_SUSPENDED; | $this->status ^= User::STATUS_SUSPENDED; | ||||
$this->save(); | $this->save(); | ||||
} | } | ||||
/** | /** | ||||
* Return users controlled by the current user. | * Return users controlled by the current user. | ||||
* | * | ||||
* Users assigned to wallets the current user controls or owns. | * @param bool $with_accounts Include users assigned to wallets | ||||
* the current user controls but not owns. | |||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Builder Query builder | * @return \Illuminate\Database\Eloquent\Builder Query builder | ||||
*/ | */ | ||||
public function users() | public function users($with_accounts = true) | ||||
{ | { | ||||
$wallets = array_merge( | $wallets = $this->wallets()->pluck('id')->all(); | ||||
$this->wallets()->pluck('id')->all(), | |||||
$this->accounts()->pluck('wallet_id')->all() | if ($with_accounts) { | ||||
); | $wallets = array_merge($wallets, $this->accounts()->pluck('wallet_id')->all()); | ||||
} | |||||
return $this->select(['users.*', 'entitlements.wallet_id']) | return $this->select(['users.*', 'entitlements.wallet_id']) | ||||
->distinct() | ->distinct() | ||||
->leftJoin('entitlements', 'entitlements.entitleable_id', '=', 'users.id') | ->leftJoin('entitlements', 'entitlements.entitleable_id', '=', 'users.id') | ||||
->whereIn('entitlements.wallet_id', $wallets) | ->whereIn('entitlements.wallet_id', $wallets) | ||||
->where('entitlements.entitleable_type', 'App\User'); | ->where('entitlements.entitleable_type', 'App\User'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |