1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace App\Models;
- use Dcat\Admin\Traits\HasDateTimeFormatter;
- use Illuminate\Auth\MustVerifyEmail;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Illuminate\Notifications\Notifiable;
- use Tymon\JWTAuth\Contracts\JWTSubject;
- class User extends Authenticatable implements JWTSubject
- {
- use Notifiable,HasDateTimeFormatter,SoftDeletes;
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $fillable = [
- 'name',
- 'email',
- 'password',
- 'lang'
- ];
- /**
- * The attributes that should be hidden for arrays.
- *
- * @var array
- */
- protected $hidden = [
- 'password',
- 'remember_token',
- 'pivot'//比赛、球队 多对多关联系统生成的额外的字段
- ];
- public function games()
- {
- return $this->belongsToMany(Game::class, 'game_users', 'user_id', 'game_id ');
- }
- public function teams()
- {
- return $this->belongsToMany(Team::class, 'team_users', 'user_id', 'team_id ');
- }
- public function user_extra(){
- return $this->hasOne(UserExtra::class,'user_id','id');
- }
- public function getJWTIdentifier()
- {
- return $this->getKey(); // TODO: Implement getJWTIdentifier() method.
- }
- public function getJWTCustomClaims()
- {
- return [
- 'role' => 'user'
- ]; // TODO: Implement getJWTCustomClaims() method.
- }
- /**
- * 设置密码加密
- * @param $value
- * @return string
- */
- public function setPasswordAttribute($value)
- {
- $this->attributes['password'] = bcrypt($value);
- }
- }
|