User.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Models;
  3. // use Illuminate\Contracts\Auth\MustVerifyEmail;
  4. use App\Models\Scopes\CompanyScope;
  5. use EloquentFilter\Filterable;
  6. use Illuminate\Database\Eloquent\Casts\Attribute;
  7. use Illuminate\Database\Eloquent\Factories\HasFactory;
  8. use Illuminate\Database\Eloquent\SoftDeletes;
  9. use Illuminate\Foundation\Auth\User as Authenticatable;
  10. use Illuminate\Notifications\Notifiable;
  11. use Laravel\Sanctum\HasApiTokens;
  12. use Spatie\Permission\Traits\HasRoles;
  13. class User extends Authenticatable
  14. {
  15. use HasApiTokens, HasFactory, Notifiable, HasRoles, SoftDeletes,Filterable;
  16. protected string $guard_name = 'api';
  17. /**
  18. * The attributes that are mass assignable.
  19. *
  20. * @var array<int, string>
  21. */
  22. protected $fillable = [
  23. 'name',
  24. 'username',
  25. 'email',
  26. 'password',
  27. 'company_id',
  28. 'department_id',
  29. 'role_id',
  30. 'created_by',
  31. 'gender',
  32. 'address',
  33. 'phone',
  34. 'status',
  35. ];
  36. /**
  37. * The attributes that should be hidden for serialization.
  38. *
  39. * @var array<int, string>
  40. */
  41. protected $hidden = [
  42. 'password',
  43. 'remember_token',
  44. ];
  45. /**
  46. * The attributes that should be cast.
  47. *
  48. * @var array<string, string>
  49. */
  50. protected $casts = [
  51. 'email_verified_at' => 'datetime',
  52. 'password' => 'hashed',
  53. ];
  54. protected function superAdmin(): Attribute
  55. {
  56. return Attribute::make(
  57. get: fn() => $this->role_id == config("auth.super_admin_role_id"),
  58. );
  59. }
  60. public function guardName(): string
  61. {
  62. return $this->guard_name;
  63. }
  64. public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  65. {
  66. return $this->belongsTo(Company::class);
  67. }
  68. public function role(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  69. {
  70. return $this->belongsTo(Role::class);
  71. }
  72. public function createdBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  73. {
  74. return $this->belongsTo(User::class, 'created_by');
  75. }
  76. public function department(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  77. {
  78. return $this->belongsTo(Department::class);
  79. }
  80. }