Admin.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Repositories\Models\Base;
  11. use App\Repositories\Models\Model;
  12. use Database\Factories\UserFactory;
  13. use Illuminate\Auth\Authenticatable;
  14. use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
  15. use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
  16. use Illuminate\Database\Eloquent\Factories\HasFactory;
  17. use Illuminate\Support\Facades\Hash;
  18. use Laravel\Lumen\Auth\Authorizable;
  19. use Spatie\Permission\Traits\HasRoles;
  20. use Tymon\JWTAuth\Contracts\JWTSubject;
  21. class Admin extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject
  22. {
  23. protected $table = 'base_admins';
  24. use Authenticatable, Authorizable, HasFactory, HasRoles;
  25. /**
  26. * The attributes that are mass assignable.
  27. *
  28. * @var array
  29. */
  30. protected $guarded = [];
  31. /**
  32. * The attributes excluded from the model's JSON form.
  33. *
  34. * @var array
  35. */
  36. protected $hidden = [
  37. 'password',
  38. ];
  39. /**
  40. * 兼容 Laravel 8 的 Factory.
  41. *
  42. * @return UserFactory
  43. */
  44. protected static function newFactory()
  45. {
  46. return UserFactory::new();
  47. }
  48. /**
  49. * Get the identifier that will be stored in the subject claim of the JWT.
  50. *
  51. * @return mixed
  52. */
  53. public function getJWTIdentifier()
  54. {
  55. return $this->getKey();
  56. }
  57. /**
  58. * Return a key value array, containing any custom claims to be added to the JWT.
  59. *
  60. * @return array
  61. */
  62. public function getJWTCustomClaims()
  63. {
  64. return ['admin'];
  65. }
  66. public function role()
  67. {
  68. return $this->belongsTo(Role::class);
  69. }
  70. public function department()
  71. {
  72. return $this->belongsTo(Department::class);
  73. }
  74. public function getHeadimgAttribute($val)
  75. {
  76. if (is_null($val)) {
  77. return path_to_url('default/headImg.jpeg');
  78. }
  79. return path_to_url($val);
  80. }
  81. }