User.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Models;
  3. // use Illuminate\Contracts\Auth\MustVerifyEmail;
  4. use App\Enums\UserLanguageSource;
  5. use App\Enums\UserTypeSource;
  6. use Illuminate\Database\Eloquent\Factories\HasFactory;
  7. use Illuminate\Foundation\Auth\User as Authenticatable;
  8. use Illuminate\Notifications\Notifiable;
  9. use Laravel\Sanctum\HasApiTokens;
  10. use Illuminate\Database\Eloquent\Relations\BelongsToMany;
  11. class User extends Authenticatable
  12. {
  13. use HasFactory, Notifiable, HasApiTokens;
  14. /**
  15. * The attributes that are mass assignable.
  16. *
  17. * @var array<int, string>
  18. */
  19. protected $fillable = [
  20. 'name',
  21. 'email',
  22. 'password',
  23. ];
  24. /**
  25. * The attributes that should be hidden for serialization.
  26. *
  27. * @var array<int, string>
  28. */
  29. protected $hidden = [
  30. 'password',
  31. 'remember_token',
  32. ];
  33. /**
  34. * Get the attributes that should be cast.
  35. *
  36. * @return array<string, string>
  37. */
  38. protected function casts(): array
  39. {
  40. return [
  41. 'email_verified_at' => 'datetime',
  42. 'password' => 'hashed',
  43. 'type' => UserTypeSource::class,
  44. 'language' => UserLanguageSource::class,
  45. ];
  46. }
  47. public function isAdmin(): bool
  48. {
  49. return $this->type === UserTypeSource::Admin;
  50. }
  51. public function isRegularUser(): bool
  52. {
  53. return $this->type === UserTypeSource::RegularUser;
  54. }
  55. public function isPayingUser(): bool
  56. {
  57. return $this->type === UserTypeSource::PayingUser;
  58. }
  59. public function isGuest(): bool
  60. {
  61. return $this->type === UserTypeSource::Guest;
  62. }
  63. public function permissions(): BelongsToMany
  64. {
  65. return $this->belongsToMany(Permission::class, 'user_type_permissions', 'user_type', 'permission_id');
  66. }
  67. }