User.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App;
  3. use Laravel\Passport\HasApiTokens;
  4. use Illuminate\Notifications\Notifiable;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. use Illuminate\Foundation\Auth\User as Authenticatable;
  7. use App\Util\RateLimit\User as UserRateLimit;
  8. use App\Services\AvatarService;
  9. class User extends Authenticatable
  10. {
  11. use Notifiable, SoftDeletes, HasApiTokens, UserRateLimit;
  12. /**
  13. * The attributes that should be mutated to dates.
  14. *
  15. * @var array
  16. */
  17. protected $casts = [
  18. 'deleted_at' => 'datetime',
  19. 'email_verified_at' => 'datetime',
  20. '2fa_setup_at' => 'datetime',
  21. 'last_active_at' => 'datetime',
  22. ];
  23. /**
  24. * The attributes that are mass assignable.
  25. *
  26. * @var array
  27. */
  28. protected $fillable = [
  29. 'name',
  30. 'username',
  31. 'email',
  32. 'password',
  33. 'app_register_ip',
  34. 'email_verified_at',
  35. 'last_active_at',
  36. 'register_source'
  37. ];
  38. /**
  39. * The attributes that should be hidden for arrays.
  40. *
  41. * @var array
  42. */
  43. protected $hidden = [
  44. 'email', 'password', 'is_admin', 'remember_token',
  45. 'email_verified_at', '2fa_enabled', '2fa_secret',
  46. '2fa_backup_codes', '2fa_setup_at', 'deleted_at',
  47. 'updated_at'
  48. ];
  49. public function profile()
  50. {
  51. return $this->hasOne(Profile::class);
  52. }
  53. public function url()
  54. {
  55. return url(config('app.url').'/'.$this->username);
  56. }
  57. public function settings()
  58. {
  59. return $this->hasOne(UserSetting::class);
  60. }
  61. public function statuses()
  62. {
  63. return $this->hasManyThrough(
  64. Status::class,
  65. Profile::class
  66. );
  67. }
  68. public function filters()
  69. {
  70. return $this->hasMany(UserFilter::class, 'user_id', 'profile_id');
  71. }
  72. public function receivesBroadcastNotificationsOn()
  73. {
  74. return 'App.User.'.$this->id;
  75. }
  76. public function devices()
  77. {
  78. return $this->hasMany(UserDevice::class);
  79. }
  80. public function storageUsedKey()
  81. {
  82. return 'profile:storage:used:' . $this->id;
  83. }
  84. public function accountLog()
  85. {
  86. return $this->hasMany(AccountLog::class);
  87. }
  88. public function interstitials()
  89. {
  90. return $this->hasMany(AccountInterstitial::class);
  91. }
  92. public function avatarUrl()
  93. {
  94. if(!$this->profile_id || $this->status) {
  95. return config('app.url') . '/storage/avatars/default.jpg';
  96. }
  97. return AvatarService::get($this->profile_id);
  98. }
  99. }