Yii2 returns an error "Call to a member function on array"

yii2 returns “Call to a member function on array” when calling a method

public function getCountForRentAgreement($id){

	$rentAgreementModel = Agreement::find()->where	(['status'=>CommonHelpers::STATUS_ACTIVE,'agreement_type'=>Agreement::ROOM_AGREEMENT_VALUE])

->andWhere([‘tenant_id’=>$id])->count();
return $rentAgreementModel;

}

How can I solve this issue?

First edit your code it is broken.
Secondly post full stack trace as it seems a problem is somewhere in a call where you are calling on array. I cannot guess where you do that without trace

public function getCountForRentAgreement($id){
    return Agreement::find()
        ->where([
             'status' => CommonHelpers::STATUS_ACTIVE,
             'agreement_type' => Agreement::ROOM_AGREEMENT_VALUE,
             'tenant_id' => $id
        ])->count();
}

You are trying to call function from array, add code from where you are calling this function. you can make this function static since you are not using $this or Object inside it.

1 Like

Issue fixed.Thank you