I have a Question, How to use Closure type Active records Query in YII2 with conditional WHERE.
Here what i want to achive:
public function getUsers($limit = 10, $type = 1, $company_id = 0) {
return User::find()->where( function($query) use ($type, $company_id){
$query->where(['type' => $type]);
if($company_id != 0) {
$query->andWhere(['company_id' => $company_id]);
}
})
->orderBy([ 'created_at'=> SORT_DESC, ])
->limit($limit);
}
Please Help if someone know about this.1