User.php 2.1 KB

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