User.php 1.7 KB

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