User.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Models;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Foundation\Auth\User as Authenticatable;
  6. use Illuminate\Notifications\Notifiable;
  7. use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;
  8. class User extends Authenticatable implements JWTSubject
  9. {
  10. use Notifiable,HasDateTimeFormatter,SoftDeletes;
  11. /**
  12. * The attributes that are mass assignable.
  13. *
  14. * @var array
  15. */
  16. protected $fillable = [
  17. 'nickname',
  18. 'email',
  19. 'avatar',
  20. 'password',
  21. 'mobile',
  22. 'open_id',
  23. 'union_id'
  24. ];
  25. //protected $guarded = [];
  26. /**
  27. * The attributes that should be hidden for arrays.
  28. *
  29. * @var array
  30. */
  31. // protected $hidden = [
  32. // 'password',
  33. // 'remember_token',
  34. // ];
  35. public function getJWTIdentifier()
  36. {
  37. return $this->getKey(); // TODO: Implement getJWTIdentifier() method.
  38. }
  39. public function getJWTCustomClaims()
  40. {
  41. return [
  42. 'role' => 'user'
  43. ]; // TODO: Implement getJWTCustomClaims() method.
  44. }
  45. /**
  46. * 设置密码加密
  47. * @param $value
  48. * @return string
  49. */
  50. public function setPasswordAttribute($value)
  51. {
  52. $this->attributes['password'] = bcrypt($value);
  53. }
  54. }