mirror of
https://github.com/v2board/v2board.git
synced 2025-01-31 02:29:14 +08:00
update
This commit is contained in:
parent
fcf95e615d
commit
2abdd2b290
@ -26,22 +26,28 @@ class UserController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function update (UserUpdate $request) {
|
public function update (UserUpdate $request) {
|
||||||
|
$fetchData = $request->only([
|
||||||
|
'email',
|
||||||
|
'password',
|
||||||
|
'transfer_enable',
|
||||||
|
'expired_at',
|
||||||
|
'banned',
|
||||||
|
'is_admin'
|
||||||
|
]);
|
||||||
$user = User::find($request->input('id'));
|
$user = User::find($request->input('id'));
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
abort(500, '用户不存在');
|
abort(500, '用户不存在');
|
||||||
}
|
}
|
||||||
if (User::where('email', $request->input('email'))->first() && $user->email !== $request->input('email')) {
|
if (User::where('email', $fetchData['email'])->first() && $user->email !== $fetchData['email']) {
|
||||||
abort(500, '邮箱已被使用');
|
abort(500, '邮箱已被使用');
|
||||||
}
|
}
|
||||||
$user->email = $request->input('email');
|
if ($fetchData['password']) {
|
||||||
if ($request->input('password')) {
|
$fetchData['password'] = password_hash($fetchData['password'], PASSWORD_DEFAULT);
|
||||||
$user->password = password_hash($request->input('password'), PASSWORD_DEFAULT);
|
} else {
|
||||||
|
unset($fetchData['password']);
|
||||||
}
|
}
|
||||||
$user->transfer_enable = $request->input('transfer_enable') * 1073741824;
|
$fetchData['transfer_enable'] = $fetchData['transfer_enable'] * 1073741824;
|
||||||
$user->expired_at = $request->input('expired_at');
|
if (!$user->update($fetchData)) {
|
||||||
$user->banned = $request->input('banned');
|
|
||||||
$user->is_admin = $request->input('is_admin');
|
|
||||||
if (!$user->save()) {
|
|
||||||
abort(500, '保存失败');
|
abort(500, '保存失败');
|
||||||
}
|
}
|
||||||
return response([
|
return response([
|
||||||
|
@ -8,4 +8,5 @@ class User extends Model
|
|||||||
{
|
{
|
||||||
protected $table = 'v2_user';
|
protected $table = 'v2_user';
|
||||||
protected $dateFormat = 'U';
|
protected $dateFormat = 'U';
|
||||||
|
protected $guarded = ['id'];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user