|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Services\AvatarService;
|
|
|
|
|
use App\Util\RateLimit\User as UserRateLimit;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
fix: add return type declarations to Eloquent relation methods
Larastan 3.x requires explicit return types on relation methods to
verify relation existence when using with(), has(), etc. This adds
the appropriate return type declarations to all relation methods
flagged by the larastan.relationExistence rule.
Models fixed:
- Profile (avatar, statuses)
- User (profile)
- Status (profile, media, hashtags)
- DirectMessage (status, author, recipient)
- Report (reporter, status, reportedUser)
- Like (actor, status)
- Media (status)
- Notification (item)
- HashtagFollow (hashtag)
- OauthClient (user)
- Story (profile)
- StatusHashtag (status, hashtag, profile, media)
- AccountInterstitial (user)
- Hashtag (posts)
- CustomFilter (keywords)
- CustomFilterKeyword (customFilter)
- AdminShadowFilter (profile)
- ImportPost (status)
4 weeks ago
|
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
use Laravel\Passport\Contracts\OAuthenticatable;
|
|
|
|
|
use Laravel\Passport\HasApiTokens;
|
|
|
|
|
use NotificationChannels\WebPush\HasPushSubscriptions;
|
|
|
|
|
|
|
|
|
|
class User extends Authenticatable implements OAuthenticatable
|
|
|
|
|
{
|
|
|
|
|
use HasApiTokens, HasFactory, HasPushSubscriptions, Notifiable, SoftDeletes, UserRateLimit;
|
|
|
|
|
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'is_admin' => 'boolean',
|
|
|
|
|
'deleted_at' => 'datetime',
|
|
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
|
'2fa_setup_at' => 'datetime',
|
|
|
|
|
'last_active_at' => 'datetime',
|
|
|
|
|
'storage_used_updated_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $guarded = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'email',
|
|
|
|
|
'password',
|
|
|
|
|
'is_admin',
|
|
|
|
|
'remember_token',
|
|
|
|
|
'email_verified_at',
|
|
|
|
|
'2fa_enabled',
|
|
|
|
|
'2fa_secret',
|
|
|
|
|
'2fa_backup_codes',
|
|
|
|
|
'2fa_setup_at',
|
|
|
|
|
'deleted_at',
|
|
|
|
|
'updated_at',
|
|
|
|
|
];
|
|
|
|
|
|
fix: add return type declarations to Eloquent relation methods
Larastan 3.x requires explicit return types on relation methods to
verify relation existence when using with(), has(), etc. This adds
the appropriate return type declarations to all relation methods
flagged by the larastan.relationExistence rule.
Models fixed:
- Profile (avatar, statuses)
- User (profile)
- Status (profile, media, hashtags)
- DirectMessage (status, author, recipient)
- Report (reporter, status, reportedUser)
- Like (actor, status)
- Media (status)
- Notification (item)
- HashtagFollow (hashtag)
- OauthClient (user)
- Story (profile)
- StatusHashtag (status, hashtag, profile, media)
- AccountInterstitial (user)
- Hashtag (posts)
- CustomFilter (keywords)
- CustomFilterKeyword (customFilter)
- AdminShadowFilter (profile)
- ImportPost (status)
4 weeks ago
|
|
|
public function profile(): HasOne
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(Profile::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function url()
|
|
|
|
|
{
|
|
|
|
|
return url(config('app.url').'/'.$this->username);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function settings()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(UserSetting::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function statuses()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasManyThrough(
|
|
|
|
|
Status::class,
|
|
|
|
|
Profile::class
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function filters()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(UserFilter::class, 'user_id', 'profile_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function receivesBroadcastNotificationsOn()
|
|
|
|
|
{
|
|
|
|
|
return 'App.User.'.$this->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function devices()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(UserDevice::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function storageUsedKey()
|
|
|
|
|
{
|
|
|
|
|
return 'profile:storage:used:'.$this->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function accountLog()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(AccountLog::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function interstitials()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(AccountInterstitial::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function avatarUrl()
|
|
|
|
|
{
|
|
|
|
|
if (! $this->profile_id || $this->status) {
|
|
|
|
|
return config('app.url').'/storage/avatars/default.jpg';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AvatarService::get($this->profile_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function routeNotificationForExpo()
|
|
|
|
|
{
|
|
|
|
|
return $this->expo_token;
|
|
|
|
|
}
|
|
|
|
|
}
|