User.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Contracts\Auth\MustVerifyEmail;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Database\Eloquent\Relations\HasMany;
  6. use Illuminate\Database\Eloquent\SoftDeletes;
  7. use Illuminate\Foundation\Auth\User as Authenticatable;
  8. use Illuminate\Notifications\Notifiable;
  9. class User extends Authenticatable implements MustVerifyEmail
  10. {
  11. use HasFactory, Notifiable, SoftDeletes;
  12. const DEFAULT_SORT_BY = 'created_at';
  13. /**
  14. * The attributes that are mass assignable.
  15. *
  16. * @var list<string>
  17. */
  18. protected $fillable = [
  19. 'name',
  20. 'email',
  21. 'notification_email',
  22. 'phone',
  23. 'password',
  24. 'role',
  25. 'color',
  26. 'token_fcm',
  27. ];
  28. /**
  29. * The attributes that should be hidden for serialization.
  30. *
  31. * @var list<string>
  32. */
  33. protected $hidden = [
  34. 'password',
  35. 'remember_token',
  36. ];
  37. /**
  38. * Get the attributes that should be cast.
  39. *
  40. * @return array<string, string>
  41. */
  42. protected function casts(): array
  43. {
  44. return [
  45. 'email_verified_at' => 'datetime',
  46. 'password' => 'hashed',
  47. ];
  48. }
  49. /**
  50. * Route notifications for the FCM channel.
  51. *
  52. * @return string
  53. */
  54. public function routeNotificationForFcm(): string
  55. {
  56. return (string)$this->token_fcm;
  57. }
  58. public function getAppInstalledAttribute(): string
  59. {
  60. return $this->token_fcm ? 'Да' : 'Нет';
  61. }
  62. public function userNotifications(): HasMany
  63. {
  64. return $this->hasMany(UserNotification::class);
  65. }
  66. public function unreadUserNotifications(): HasMany
  67. {
  68. return $this->userNotifications()->whereNull('read_at');
  69. }
  70. }