User.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Models;
  3. use Tymon\JWTAuth\Contracts\JWTSubject;
  4. use Illuminate\Notifications\Notifiable;
  5. use Illuminate\Foundation\Auth\User as Authenticatable;
  6. use Auth;
  7. use Spatie\Permission\Traits\HasRoles;
  8. /**
  9. * 这个类要继承接口-用户 model
  10. * Class User
  11. * @package App\Models
  12. */
  13. class User extends Authenticatable implements JWTSubject
  14. {
  15. use Notifiable;
  16. protected $table = 'vr_users';
  17. /**
  18. * The attributes that are mass assignable.
  19. *
  20. * @var array
  21. */
  22. protected $fillable = [
  23. 'open_id', 'phone', 'user_type', 'real_name', 'nick_name', 'avatar_url', 'gender', 'birthday', 'password', 'session_key', 'country', 'province', 'city', 'is_graduate', 'website_id', 'become_member_time','carbon_emission',
  24. ];
  25. /**
  26. * The attributes that should be hidden for arrays.
  27. *
  28. * @var array
  29. */
  30. protected $hidden = [
  31. 'password',
  32. ];
  33. /**
  34. * The attributes that should be cast to native types.
  35. *
  36. * @var array
  37. */
  38. protected $casts = [
  39. 'created_at' => 'datetime',
  40. 'updated_at' => 'datetime',
  41. 'deleted_at' => 'datetime',
  42. ];
  43. public function getJWTIdentifier()
  44. {
  45. return $this->getKey();
  46. }
  47. /**
  48. * Return a key value array, containing any custom claims to be added to the JWT.
  49. *
  50. * @return array
  51. */
  52. public function getJWTCustomClaims()
  53. {
  54. return [];
  55. }
  56. public function routeNotificationForEasySms()
  57. {
  58. return $this->phone;
  59. }
  60. public function userCourses()
  61. {
  62. return $this->hasMany(UserCourses::class);
  63. }
  64. public function userWebsites()
  65. {
  66. // return $this->hasOne(Website::class,'id','website_id');
  67. return $this->belongsTo(Website::class, 'id', 'website_id');
  68. }
  69. }