update roles
This commit is contained in:
parent
af5dceb6c0
commit
98e8501f53
|
|
@ -36,11 +36,13 @@ class AdminUserController extends Controller
|
|||
|
||||
public function update(Request $request, int $adminUserId)
|
||||
{
|
||||
return json_success('更新成功');
|
||||
$adminUser = AdminUserRepo::updateAdminUser($request->toArray());
|
||||
return json_success('更新成功', $adminUser);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, int $adminUserId)
|
||||
{
|
||||
AdminUserRepo::deleteAdminUser($adminUserId);
|
||||
return json_success('删除成功');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,11 +20,38 @@ class AdminUserRepo
|
|||
$adminUser = new AdminUser([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => bcrypt($data['password'])
|
||||
'password' => bcrypt($data['password']),
|
||||
'active' => true,
|
||||
]);
|
||||
$adminUser->save();
|
||||
|
||||
$adminUser->assignRole($data['roles']);
|
||||
return $adminUser;
|
||||
}
|
||||
|
||||
|
||||
public static function updateAdminUser($data): AdminUser
|
||||
{
|
||||
$id = $data['id'] ?? 0;
|
||||
$password = $data['password'] ?? '';
|
||||
$adminUser = AdminUser::query()->find($id);
|
||||
$userData = [
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'active' => true,
|
||||
];
|
||||
if ($password) {
|
||||
$userData['password'] = bcrypt($password);
|
||||
}
|
||||
$adminUser->update($userData);
|
||||
$adminUser->syncRoles($data['roles']);
|
||||
return $adminUser;
|
||||
}
|
||||
|
||||
|
||||
public static function deleteAdminUser($adminUserId)
|
||||
{
|
||||
$adminUser = AdminUser::query()->find($adminUserId);
|
||||
$adminUser->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue