Changeset View
Changeset View
Standalone View
Standalone View
src/app/User.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use App\Entitlement; | |||||
use App\UserAlias; | use App\UserAlias; | ||||
use App\Traits\UserAliasesTrait; | use App\Traits\UserAliasesTrait; | ||||
use App\Traits\UserSettingsTrait; | use App\Traits\UserSettingsTrait; | ||||
use Illuminate\Notifications\Notifiable; | use Illuminate\Notifications\Notifiable; | ||||
use Illuminate\Contracts\Auth\MustVerifyEmail; | use Illuminate\Contracts\Auth\MustVerifyEmail; | ||||
use Illuminate\Database\Eloquent\SoftDeletes; | use Illuminate\Database\Eloquent\SoftDeletes; | ||||
use Illuminate\Foundation\Auth\User as Authenticatable; | use Illuminate\Foundation\Auth\User as Authenticatable; | ||||
use Iatstuti\Database\Support\NullableFields; | use Iatstuti\Database\Support\NullableFields; | ||||
▲ Show 20 Lines • Show All 343 Lines • ▼ Show 20 Lines | class User extends Authenticatable implements JWTSubject | ||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
*/ | */ | ||||
public function settings() | public function settings() | ||||
{ | { | ||||
return $this->hasMany('App\UserSetting', 'user_id'); | return $this->hasMany('App\UserSetting', 'user_id'); | ||||
} | } | ||||
/** | /** | ||||
* Return users controlled (owned) by the current user, including himself. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Builder Query builder | |||||
*/ | |||||
public function users() | |||||
{ | |||||
// FIXME: I didn't find a nicer way (using ORM) to build that query | |||||
// Also, my SQL skills must have been reduced, | |||||
// I don't know why distinct() is needed here, but | |||||
vanmeeuwen: This should really be:
```
return $this->select(['users.*', 'entitlements.wallet_id'])
```… | |||||
// without it the query returns duplicates. | |||||
return $this->select('users.*') | |||||
->leftJoin('entitlements', 'entitlements.entitleable_id', '=', 'users.id') | |||||
->where('entitlements.owner_id', $this->id) | |||||
->where('entitlements.entitleable_type', 'App\User') | |||||
->orWhere('users.id', $this->id) | |||||
->distinct(); | |||||
} | |||||
/** | |||||
* Verification codes for this user. | * Verification codes for this user. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
*/ | */ | ||||
public function verificationcodes() | public function verificationcodes() | ||||
{ | { | ||||
return $this->hasMany('App\VerificationCode', 'user_id', 'id'); | return $this->hasMany('App\VerificationCode', 'user_id', 'id'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |
This should really be:
because Query\Builder::select() only supports 0-1 parameters (see phpstan output).