74 lines
1.7 KiB
PHP
74 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models\User;
|
|
|
|
use App\Core\Model;
|
|
use App\Models\Permission\Role;
|
|
use Illuminate\Auth\Authenticatable;
|
|
use Tymon\JWTAuth\Contracts\JWTSubject;
|
|
use App\Models\Permission\Traits\HasRoles;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Dipper\Foundation\Snowflake\SnowflakeHelpers;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
|
|
|
/**
|
|
* 用户
|
|
*/
|
|
class User extends Model implements AuthenticatableContract, JWTSubject
|
|
{
|
|
use HasRoles, SnowflakeHelpers, SoftDeletes, Authenticatable;
|
|
|
|
protected $table = 'users';
|
|
|
|
public $incrementing = false;
|
|
|
|
protected $fillable = ['appid', 'username', 'password', 'email', 'mobile', 'nickname'];
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
static::saving(function ($model) {
|
|
unset($model['avatar']);
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* A model may have roles.
|
|
*/
|
|
public function roles(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Role::class, 'user_has_roles', 'uid', 'role_id');
|
|
}
|
|
|
|
/**
|
|
* Get the identifier that will be stored in the subject claim of the JWT.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function getJWTIdentifier()
|
|
{
|
|
return $this->getKey();
|
|
}
|
|
|
|
/**
|
|
* Return a key value array, containing any custom claims to be added to the JWT.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getJWTCustomClaims()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* 用户关联信息
|
|
*/
|
|
public function info(): HasOne
|
|
{
|
|
return $this->hasOne(Info::class, 'uid', 'id');
|
|
}
|
|
}
|