first commit
This commit is contained in:
97
modules/Member/app/Models/Member.php
Normal file
97
modules/Member/app/Models/Member.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?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 Modules\Member\Models;
|
||||
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class Member extends Authenticatable implements JWTSubject {
|
||||
use Notifiable;
|
||||
|
||||
protected $table = 'member';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $fillable = ['username', 'nickname', 'email', 'mobile', 'password', 'status'];
|
||||
protected $hidden = ['password', 'deleted_at'];
|
||||
protected $dateFormat = 'Y-m-d H:i:s';
|
||||
protected $with = ['invite:uid,nickname,username,level_id', 'extend', 'level', 'store', 'social', 'pm'];
|
||||
|
||||
/**
|
||||
* 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 [];
|
||||
}
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
'deleted_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
}
|
||||
|
||||
public function password() : Attribute {
|
||||
return new Attribute(
|
||||
set: fn ($value) => Hash::make($value),
|
||||
);
|
||||
}
|
||||
|
||||
public function avatar(): Attribute {
|
||||
return new Attribute(
|
||||
get: fn ($value) => $value ?? request()->root() . '/storage/avatar/default_avatar.jpg',
|
||||
);
|
||||
}
|
||||
|
||||
public function routeNotificationForMail(Notification $notification): array|string{
|
||||
return [$this->email => $this->nickname];
|
||||
}
|
||||
|
||||
public function invite(){
|
||||
return $this->hasOne(Member::class, 'uid', 'invite_uid');
|
||||
}
|
||||
|
||||
public function extend(){
|
||||
return $this->hasOne(MemberExtends::class, 'member_id', 'uid');
|
||||
}
|
||||
|
||||
public function social(){
|
||||
return $this->hasMany(\Modules\Wechat\Models\MemberSocial::class, 'member_id', 'uid');
|
||||
}
|
||||
|
||||
public function level(){
|
||||
return $this->hasOne(MemberLevel::class, 'id', 'level_id');
|
||||
}
|
||||
|
||||
public function address(){
|
||||
return $this->hasMany(MemberAddress::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
public function pm(){
|
||||
return $this->hasOne(Pm::class, 'member_id', 'pm_uid');
|
||||
}
|
||||
|
||||
public function store(){
|
||||
return $this->hasOne(Store::class, 'member_id', 'store_uid');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user