join('Questions q', 'p.questions_id=q.id') ->where(['p.type' => $type, 'p.test_id' => $test_id, 'q.is_del' => 0]); if ($question_type) { $model = $model->where('p.question_type', $question_type); } $list = $model->field('p.*,q.option,q.stem,q.image,q.answer,q.difficulty,q.analysis,q.relation,q.is_img,q.is_del') ->order('p.sort desc')->select(); $list = count($list) > 0 ? $list->toArray() : []; return $list; } }