调整登录返回的权限ID组
parent
1ffec7bb41
commit
b1d17622ff
|
|
@ -23,13 +23,19 @@ class AdminUserController extends Controller
|
|||
public function store(AdminUserRequest $request)
|
||||
{
|
||||
$baseIds = $request->input('base_ids', []);
|
||||
if(AdminUser::where('username', $request->input('username'))->exists()){
|
||||
return $this->error('该登录名已存在');
|
||||
}
|
||||
try{
|
||||
DB::beginTransaction();
|
||||
//添加管理员信息
|
||||
$password = bcrypt($request->input('password'));
|
||||
$user = AdminUser::create(array_merge(['password'=> $password], $request->input()));
|
||||
$input = $request->input();
|
||||
$input['password'] = bcrypt($request->input('password'));
|
||||
$user = AdminUser::create($input);
|
||||
//添加管理员查看基地的数据权限;
|
||||
$user->bases()->sync($baseIds);
|
||||
//添加管理员角色关联;
|
||||
$user->roles()->sync($request->input('role_id'));
|
||||
DB::commit();
|
||||
}catch(\Throwable $th){
|
||||
DB::rollBack();
|
||||
|
|
@ -46,12 +52,17 @@ class AdminUserController extends Controller
|
|||
public function update(AdminUser $adminUser, AdminUserUpdateRequest $request)
|
||||
{
|
||||
$baseIds = $request->input('base_ids', []);
|
||||
if(AdminUser::where('username', $request->input('username'))->where('id', '<>', $adminUser->id)->exists()){
|
||||
return $this->error('该登录名已存在');
|
||||
}
|
||||
try{
|
||||
DB::beginTransaction();
|
||||
//添加管理员信息
|
||||
$adminUser->update($request->input());
|
||||
//添加管理员查看基地的数据权限;
|
||||
$adminUser->crops()->sync($baseIds);
|
||||
//添加管理员角色关联;
|
||||
$adminUser->roles()->sync($request->input('role_id'));
|
||||
DB::commit();
|
||||
}catch(\Throwable $th){
|
||||
DB::rollBack();
|
||||
|
|
@ -68,6 +79,7 @@ class AdminUserController extends Controller
|
|||
try{
|
||||
DB::beginTransaction();
|
||||
$adminUser->crops()->sync([]);
|
||||
$adminUser->roles()->sync([]);
|
||||
$adminUser->delete();
|
||||
DB::commit();
|
||||
}catch(\Throwable $th){
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ class AuthController extends Controller
|
|||
protected function attemptUser(AdminUser $user, $name = 'api')
|
||||
{
|
||||
$token = $user->createToken($name)->plainTextToken;
|
||||
|
||||
return $this->json(['token' => $token, 'info' => $user, 'permissions' => $user->getCachePermissions()]);
|
||||
return $this->json(['token' => $token, 'info' => $user, 'permissions' => $user->permissionIds()]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,4 +25,8 @@ class AdminUser extends BaseAdminModel
|
|||
public function bases(){
|
||||
return $this->belongsToMany(AgriculturalBase::class, 'admin_user_bases', 'user_id', 'base_id');
|
||||
}
|
||||
|
||||
public function permissionIds(){
|
||||
return $this->getCachePermissions()->pluck('id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue