Skip to content

Commit 3f3d225

Browse files
committed
fix(model): 访问器和修改器 uid 字段
1 parent 1c51d3f commit 3f3d225

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

laravel/app/Models/ApiExcel.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,28 @@ public function apiParam()
3333
{
3434
return $this->belongsTo(ApiParam::class, 'api_param_id');
3535
}
36+
37+
/**
38+
* 访问器--访问用户名
39+
*
40+
* @param $uid
41+
*
42+
* @return mixed|string
43+
*/
44+
public function getUidAttribute($uid)
45+
{
46+
$user = \App\User::where('id', $uid)->first(['name']);
47+
return $user->name ?? '';
48+
}
49+
50+
/**
51+
* 修改器--修改为用户 id
52+
*
53+
* @param $uid
54+
*/
55+
public function setUidAttribute($uid)
56+
{
57+
// 根据 jwt 查询用户 ID
58+
$this->attributes['uid'] = auth('api')->user()['id'];
59+
}
3660
}

0 commit comments

Comments
 (0)