User.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. 'fs_password',
  36. ];
  37. /**
  38. * The attributes that should be hidden for serialization.
  39. *
  40. * @var array<int, string>
  41. */
  42. protected $hidden = [
  43. 'password',
  44. 'remember_token',
  45. ];
  46. /**
  47. * The attributes that should be cast.
  48. *
  49. * @var array<string, string>
  50. */
  51. protected $casts = [
  52. 'email_verified_at' => 'datetime',
  53. 'password' => 'hashed',
  54. ];
  55. protected function superAdmin(): Attribute
  56. {
  57. return Attribute::make(
  58. get: fn() => $this->role_id == config("auth.super_admin_role_id"),
  59. );
  60. }
  61. public function guardName(): string
  62. {
  63. return $this->guard_name;
  64. }
  65. public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  66. {
  67. return $this->belongsTo(Company::class);
  68. }
  69. public function role(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  70. {
  71. return $this->belongsTo(Role::class);
  72. }
  73. public function createdBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  74. {
  75. return $this->belongsTo(User::class, 'created_by');
  76. }
  77. public function department(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  78. {
  79. return $this->belongsTo(Department::class);
  80. }
  81. }