User.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\SoftDeletes;
  4. use Illuminate\Foundation\Auth\User as Authenticatable;
  5. use Illuminate\Notifications\Notifiable;
  6. use Spatie\Activitylog\Traits\LogsActivity;
  7. use Tymon\JWTAuth\Contracts\JWTSubject;
  8. class User extends Authenticatable implements JWTSubject
  9. {
  10. use Notifiable, SoftDeletes,LogsActivity;
  11. // 指定 LogsActivity 记录名
  12. protected static $logName = 'Model';
  13. protected static $logAttributes = ['*'];
  14. /**
  15. * The attributes that are mass assignable.
  16. *
  17. * @var array
  18. */
  19. protected $fillable = [
  20. 'mobile', 'password', 'pid', 'tencent_im_user_id','sex','status','is_vip','is_auth','remember_token','ycode','latitude','longitude','online','notice_status','like_num','like_me_num','look_num','lock_pass','is_distory','registrationId','phoneModel'
  21. ];
  22. /**
  23. * The attributes that should be hidden for arrays.
  24. *
  25. * @var array
  26. */
  27. protected $hidden = [
  28. 'password',
  29. 'remember_token',
  30. ];
  31. public function getJWTIdentifier()
  32. {
  33. return $this->getKey(); // TODO: Implement getJWTIdentifier() method.
  34. }
  35. public function getJWTCustomClaims()
  36. {
  37. return [
  38. 'role' => 'user'
  39. ]; // TODO: Implement getJWTCustomClaims() method.
  40. }
  41. /**
  42. * 设置密码加密
  43. * @param $value
  44. * @return string
  45. */
  46. public function setPasswordAttribute($value)
  47. {
  48. file_put_contents('password.log','----'.date('Y-m-d H:i:s').'----'.var_export($value,true).PHP_EOL,FILE_APPEND);
  49. $this->attributes['password'] = bcrypt($value);
  50. file_put_contents('password.log','----'.date('Y-m-d H:i:s').'--加密后--'.var_export($this->attributes['password'],true).PHP_EOL,FILE_APPEND);
  51. }
  52. public function user_info()
  53. {
  54. return $this->belongsTo(UserInfoModel::class,'id','user_id');
  55. }
  56. }