User.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Repositories\Models\User;
  3. use App\Repositories\Models\Model;
  4. use Database\Factories\UserFactory;
  5. use Illuminate\Auth\Authenticatable;
  6. use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
  7. use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
  8. use Illuminate\Database\Eloquent\Factories\HasFactory;
  9. use Laravel\Lumen\Auth\Authorizable;
  10. use Spatie\Permission\Traits\HasRoles;
  11. use Tymon\JWTAuth\Contracts\JWTSubject;
  12. /**
  13. * Class Student.
  14. *
  15. * @package namespace App\Repositories\Models\User;
  16. */
  17. class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject
  18. {
  19. use Authenticatable, Authorizable, HasFactory, HasRoles;
  20. protected $table = 'base_admins';
  21. /**
  22. * The attributes that are mass assignable.
  23. *
  24. * @var array
  25. */
  26. protected $guarded = [];
  27. protected $hidden = ['password'];
  28. /**
  29. * 兼容 Laravel 8 的 Factory.
  30. *
  31. * @return UserFactory
  32. */
  33. protected static function newFactory()
  34. {
  35. return UserFactory::new();
  36. }
  37. /**
  38. * Get the identifier that will be stored in the subject claim of the JWT.
  39. *
  40. * @return mixed
  41. */
  42. public function getJWTIdentifier()
  43. {
  44. return $this->getKey();
  45. }
  46. /**
  47. * Return a key value array, containing any custom claims to be added to the JWT.
  48. *
  49. * @return array
  50. */
  51. public function getJWTCustomClaims()
  52. {
  53. return ['user'];
  54. }
  55. }