User.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Models;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Auth\MustVerifyEmail;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. use Illuminate\Foundation\Auth\User as Authenticatable;
  7. use Illuminate\Notifications\Notifiable;
  8. use Tymon\JWTAuth\Contracts\JWTSubject;
  9. class User extends Authenticatable implements JWTSubject
  10. {
  11. use Notifiable,HasDateTimeFormatter,SoftDeletes;
  12. /**
  13. * The attributes that are mass assignable.
  14. *
  15. * @var array
  16. */
  17. protected $fillable = [
  18. 'name',
  19. 'email',
  20. 'password',
  21. 'lang'
  22. ];
  23. /**
  24. * The attributes that should be hidden for arrays.
  25. *
  26. * @var array
  27. */
  28. protected $hidden = [
  29. 'password',
  30. 'remember_token',
  31. 'pivot'//比赛、球队 多对多关联系统生成的额外的字段
  32. ];
  33. public function games()
  34. {
  35. return $this->belongsToMany(Game::class, 'game_users', 'user_id', 'game_id ');
  36. }
  37. public function teams()
  38. {
  39. return $this->belongsToMany(Team::class, 'team_users', 'user_id', 'team_id ');
  40. }
  41. public function user_extra(){
  42. return $this->hasOne(UserExtra::class,'user_id','id');
  43. }
  44. public function getJWTIdentifier()
  45. {
  46. return $this->getKey(); // TODO: Implement getJWTIdentifier() method.
  47. }
  48. public function getJWTCustomClaims()
  49. {
  50. return [
  51. 'role' => 'user'
  52. ]; // TODO: Implement getJWTCustomClaims() method.
  53. }
  54. /**
  55. * 设置密码加密
  56. * @param $value
  57. * @return string
  58. */
  59. public function setPasswordAttribute($value)
  60. {
  61. $this->attributes['password'] = bcrypt($value);
  62. }
  63. }