Files
account/app/Models/Auth/Admin.php
2026-01-18 09:52:48 +08:00

61 lines
1.8 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace App\Models\Auth;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Support\Facades\Hash;
use App\Traits\ModelTrait;
class Admin extends Authenticatable implements JWTSubject {
use Notifiable, ModelTrait;
protected $table = 'auth_admins';
protected $primaryKey = 'uid';
protected $fillable = ['username', 'nickname', 'email', 'mobile', 'password', 'department_id', 'status', 'last_login_at', 'last_login_ip'];
protected $hidden = ['password', 'deleted_at'];
protected $with = ['department', 'roles'];
// Rest omitted for brevity
/**
* 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 password() : Attribute {
return new Attribute(
set: fn ($value) => Hash::make($value),
);
}
public function department(){
return $this->belongsTo(Department::class, 'department_id', 'id');
}
public function roles(){
return $this->belongsToMany(Role::class, 'auth_admins_roles', 'uid', 'role_id');
}
}