User.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. ];
  25. /**
  26. * The attributes that should be hidden for serialization.
  27. *
  28. * @var array<int, string>
  29. */
  30. protected $hidden = [
  31. 'password',
  32. 'remember_token',
  33. ];
  34. /**
  35. * The attributes that should be cast.
  36. *
  37. * @var array<string, string>
  38. */
  39. protected $casts = [
  40. 'email_verified_at' => 'datetime',
  41. 'password' => 'hashed',
  42. ];
  43. public function guardName(): string
  44. {
  45. return $this->guard_name;
  46. }
  47. public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  48. {
  49. return $this->belongsTo(Company::class);
  50. }
  51. public function role(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  52. {
  53. return $this->belongsTo(Role::class);
  54. }
  55. public function createdBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo
  56. {
  57. return $this->belongsTo(User::class, 'created_by');
  58. }
  59. }