User.php 2.0 KB

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