app/Api/V1/Controllers/UserController.php
/**
     * lock an internal user with a passed user id
     *
     * @param LockUserRequest $request
     *
     * @return json response
     * @throws \Exception
     */
lock an internal user with a passed user id
@param LockUserRequest $request

@return json response
@throws \Exception
lock an internal user with a passed user id @param LockUserRequest $request @return json response @throws \ Exception
public function lockUserById(LockUserRequest $request, $id)
    {
        if (!($user = InternalUser::query()->where('user_id', $id)->first()) && !($user = Vendor::query()->where('user_id', $id)->first())) {
            throw new NotFoundHttpException('The user\'s details is not found.');
        }
        $admin = self::getAdminDetails($this->authUser());
        if (!$admin) return $this->forbidden("Your identity cannot be verified at the moment, please try again.");
        if ($user->user_id == $admin->user_id) {
            throw new BadRequestHttpException('You cannot lock yourself.');
        }
        if (!$user instanceof Vendor && ($user->userObject())->isSuperAdmin() && !$admin->userObject()->isSuperAdmin()) {
            return $this->withMessage("You do not have enough permission to lock this user", 403);
        }
        if ($user->is_locked == 1) {
            IsLocked::query()->where('user_id', $user->user_id)->delete();
            $user->is_locked = 0;
        } else {
            IsLocked::query()->create(['user_id' => $user->id, 'reason' => $request->reason]);
            $user->is_locked = 1;
        }
        if ($user->save()) {
            event(new LockUserAccount($admin, $user));
            return $this->withJson(['is_locked' => $user->is_locked]);
        }
        throw new UpdateResourceFailedException('User account lock failed');
    }
public function lockUserById ( LockUserRequest $ request , $ id ) { if ( ! ( $ user = InternalUser :: query ( ) -> where ( 'user_id' , $ id ) -> first ( ) ) && ! ( $ user = Vendor :: query ( ) -> where ( 'user_id' , $ id ) -> first ( ) ) ) { throw new NotFoundHttpException ( 'The user\'s details is not found.' ) ; } $ admin = self :: getAdminDetails ( $ this -> authUser ( ) ) ; if ( ! $ admin ) return $ this -> forbidden ( " Your identity cannot be verified at the moment, please try again. " ) ; if ( $ user -> user_id == $ admin -> user_id ) { throw new BadRequestHttpException ( 'You cannot lock yourself.' ) ; } if ( ! $ user instanceof Vendor && ( $ user -> userObject ( ) ) -> isSuperAdmin ( ) && ! $ admin -> userObject ( ) -> isSuperAdmin ( ) ) { return $ this -> withMessage ( " You do not have enough permission to lock this user " , 403 ) ; } if ( $ user -> is_locked == 1 ) { IsLocked :: query ( ) -> where ( 'user_id' , $ user -> user_id ) -> delete ( ) ; $ user -> is_locked = 0 ; } else { IsLocked :: query ( ) -> create ( [ 'user_id' => $ user -> id , 'reason' => $ request -> reason ] ) ; $ user -> is_locked = 1 ; } if ( $ user -> save ( ) ) { event ( new LockUserAccount ( $ admin , $ user ) ) ; return $ this -> withJson ( [ 'is_locked' => $ user -> is_locked ] ) ; } throw new UpdateResourceFailedException ( 'User account lock failed' ) ; }
lock an internal user with a passed user id
 @param LockUserRequest $request
lock an internal user with a passed user id @param LockUserRequest $request
//note that users (admin) must have been authenticated before this call