skip to Main Content
public function actionItemsenbale($organization_id) {

    $items = Item::updateAll(['is_rtm_enable' => SharedConstant::VALUE_ZERO])->andWhere(['organization_id' => $organization_id]);
    return (new ApiResponse)->success(['item' => $items]);
}

2

Answers


  1. updateAll does not return data. It only returns the count of data that was updated.

    After you check if data was updated, do another find() with your filters and return that.

    public function actionItemsenbale($organization_id) {
    
        $ctr = Item::updateAll(['is_rtm_enable' => SharedConstant::VALUE_ZERO],['organization_id' => $organization_id]);
        if($ctr>0)
            return (new ApiResponse)->success(['items' => Item::find()->where(['organization_id' => $organization_id])->all()]);
        //else
        //    return (new ApiResponse)->failure(['error' => 'nothing enabled']);
    }
    

    I am only guessing your query as I dont know ApiResponse and weather it accepts Item objects or just array like ->asArray()->all().

    Login or Signup to reply.
  2. public function actionItemsenbale($organization_id) {
        $items = Item->find()->where([
            'organization_id' => $organization_id
        ])
        ->all();
    
        if (count($items) > 0) {
            $item_ids = [];
    
            foreach ($items as $item) {
                $item->updateAttributes(['is_rtm_enable' => SharedConstant::VALUE_ZERO]);
                $item_ids[] = $item->id; // Or whatever what you want to send in response
            }
            //If You need, process $item_ids array before send- response 
            return (new ApiResponse)->success(['item' => $item_ids]);
        }
        
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search