User.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. class User extends Authenticatable
  9. {
  10. use Notifiable, SoftDeletes, HasApiTokens, UserRateLimit;
  11. /**
  12. * The attributes that should be mutated to dates.
  13. *
  14. * @var array
  15. */
  16. protected $dates = ['deleted_at', 'email_verified_at', '2fa_setup_at'];
  17. /**
  18. * The attributes that are mass assignable.
  19. *
  20. * @var array
  21. */
  22. protected $fillable = [
  23. 'name', 'username', 'email', 'password',
  24. ];
  25. /**
  26. * The attributes that should be hidden for arrays.
  27. *
  28. * @var array
  29. */
  30. protected $hidden = [
  31. 'email', 'password', 'is_admin', 'remember_token',
  32. 'email_verified_at', '2fa_enabled', '2fa_secret',
  33. '2fa_backup_codes', '2fa_setup_at', 'deleted_at',
  34. 'updated_at'
  35. ];
  36. public function profile()
  37. {
  38. return $this->hasOne(Profile::class);
  39. }
  40. public function url()
  41. {
  42. return url(config('app.url').'/'.$this->username);
  43. }
  44. public function settings()
  45. {
  46. return $this->hasOne(UserSetting::class);
  47. }
  48. public function statuses()
  49. {
  50. return $this->hasManyThrough(
  51. Status::class,
  52. Profile::class
  53. );
  54. }
  55. public function filters()
  56. {
  57. return $this->hasMany(UserFilter::class);
  58. }
  59. public function receivesBroadcastNotificationsOn()
  60. {
  61. return 'App.User.'.$this->id;
  62. }
  63. public function devices()
  64. {
  65. return $this->hasMany(UserDevice::class);
  66. }
  67. public function storageUsedKey()
  68. {
  69. return 'profile:storage:used:' . $this->id;
  70. }
  71. }