/** * @param $inputs */ public function store($inputs) { $answersLabels = $inputs['answerLabel']; $answers = []; foreach ($answersLabels as $key => $answersLabel) { //Creating Answer object $answerEntity = new Answer(); $answerEntity->setAttribute('label', $answersLabel); if ($key == $inputs['answerChecked']) { $answerEntity->setAttribute('correct', true); } else { $answerEntity->setAttribute('correct', false); } $answers[] = $answerEntity; } //Insert the question $question = new Question(); $question->fill($inputs); $question->save(); //Attach this question to one or several quizzs if (isset($inputs['quizz'])) { $question->quizzs()->attach($inputs['quizz']); } //Insert all the answers to this question $question->answers()->saveMany($answers); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(AnswerRequest $request) { $comment = new Answer(); $comment->text = $request->text; $comment->question_id = $request->question_id; $comment->user_id = Auth::user()->id; if ($comment->save()) { Event::fire(new CreateComment($request->type, $request->question_id, $request->user_id, $comment->id)); } return \Redirect::to('/questions/' . $request->question_id); }
public function action(Request $request) { $quizz = $this->quizzRepository->getActif(); $answer = Answer::find($request->get('answer')); if (!$answer) { return redirect('/question', 302, [], true)->with('status', 'Vous devez cochez au moins une réponse'); } $answeredQuestionNbr = $this->scoreRepository->getAnsweredQuestionNbr($quizz); if ($answeredQuestionNbr < $quizz->max_question) { $unansweredQuestion = $this->scoreRepository->getUnansweredQuestion($quizz); $this->scoreRepository->checkAndStore($answer, $unansweredQuestion); $answeredQuestions = $this->scoreRepository->getAnsweredQuestions($quizz); foreach ($quizz->questions as $key => $question) { foreach ($answeredQuestions as $answeredQuestion) { if ($question->id == $answeredQuestion->question->id) { $quizz->questions->forget($key); } } } if ($quizz->questions->isEmpty()) { return redirect('/result', 302, [], true); } else { $question = $quizz->questions->random(1); $this->scoreRepository->storeUnansweredQuestion($quizz, $question); } return redirect('/question', 302, [], true); } return redirect('/result', 302, [], true); }
/** * Show the form for creating a new resource. * * @return Response */ public function answer(Request $request, Test $Test, Question $Question) { foreach ($request->input('answers', []) as $answer) { $Answer = Answer::find($answer); $Test->answers()->attach($Answer); } return redirect(route('client.test', $Test)); }
public function actionIndex() { $file = file_get_contents(__DIR__ . '/QuestionImport.txt'); $line = explode("\n", $file); $array = []; foreach ($line as $k => $v) { $el = explode("\t", $v); $count_el = count($el); $array[$k]['title'] = $el[0]; $array[$k]['occured_number'] = $el[1]; $array[$k]['correct_answer_key'] = $el[2]; for ($i = 3; $i < $count_el; $i++) { $array[$k]['answer'][$i] = $el[$i]; } $array[$k]['number_of_elements'] = $count_el; } $user = User::findByUsername('admin'); foreach ($array as $v) { $model_question = new Question(); $model_question->title = $v['title']; $model_question->occured_number = $v['occured_number']; $model_question->correct_answer_id = '0'; $model_question->author_id = $user->id; $model_question->save(); $correct_answer_id = 0; foreach ($v['answer'] as $k2 => $v2) { $model_answer = new Answer(); $model_answer->question_id = $model_question->id; $model_answer->title = $v2; $model_answer->author_id = $user->id; $model_answer->save(); if ($k2 - 3 == $v['correct_answer_key']) { $correct_answer_id = $model_answer->id; } } $model_question->correct_answer_id = $correct_answer_id; $model_question->save(); } }
public function updateAnswer(AnswerRequest $request, Answer $answer) { $input = $request->all(); $application = Application::find($input['application_id']); if ($answer->user->id != Auth::user()->id) { $request->session()->flash('error', 'Only the person who created an application may answer questions for it.'); return redirect('/login'); } if ($answer->application->status != 'new') { $request->session()->flash('error', 'Your application has been submitted, you may no longer make changes.'); return redirect('/applications/' . $application->id . '/review'); } $answer->update($input); // Check if a file needs to be uploaded if ($answer->question->type == 'file') { // Save uploaded file $upload = Document::handleUpload($request); // Save new document Document::createDocument($application, $upload, $answer); } $request->session()->flash('success', 'Your answer has been saved.'); return redirect('/applications/' . $answer->application->id); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Answer::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'is_correct' => $this->is_correct, 'question_id' => $this->question_id]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Answer::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'askId' => $this->askId, 'userId' => $this->userId, 'createTime' => $this->createTime, 'status' => $this->status, 'helpNum' => $this->helpNum]); $query->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function comment(Request $request) { if ($request->has('answer_id')) { $answer = Answer::find($request->input('answer_id')); $comment = $answer->comments()->create(['body' => $request->input('body')]); $comment->user()->associate(\Auth::user())->save(); } else { if ($request->has('question_id')) { $question = Question::find($request->input('question_id')); $comment = $question->comments()->create(['body' => $request->input('body')]); $comment->user()->associate(\Auth::user())->save(); } } return back(); }
public function run() { DB::table('answers')->delete(); Answer::create(['student_id' => 1, 'question_id' => 51, 'option_id' => 201]); Answer::create(['student_id' => 1, 'question_id' => 53, 'option_id' => 209]); Answer::create(['student_id' => 1, 'question_id' => 54, 'option_id' => 216]); Answer::create(['student_id' => 1, 'question_id' => 55, 'option_id' => 219]); Answer::create(['student_id' => 2, 'question_id' => 51, 'option_id' => 201]); Answer::create(['student_id' => 2, 'question_id' => 52, 'option_id' => 205]); Answer::create(['student_id' => 2, 'question_id' => 53, 'option_id' => 210]); Answer::create(['student_id' => 2, 'question_id' => 56, 'option_id' => 223]); Answer::create(['student_id' => 3, 'question_id' => 52, 'option_id' => 207]); Answer::create(['student_id' => 3, 'question_id' => 54, 'option_id' => 214]); Answer::create(['student_id' => 3, 'question_id' => 55, 'option_id' => 218]); Answer::create(['student_id' => 3, 'question_id' => 56, 'option_id' => 224]); }
public function like(Request $request) { $answer = Answer::findOrFail($request->input('answer_id')); $message = []; if ($answer->likes()->find(\Auth::user()->id)) { $this->dispatch(new RemoveLikeFromAnswer($answer, \Auth::user())); $message['type'] = 'dislike'; } else { $this->dispatch(new AddLikeToAnswer($answer, \Auth::user())); $message['type'] = 'like'; } if ($request->ajax()) { $message['count'] = $answer->likes->count(); return $message; } return back(); }
public function show($id){ try{ $s = ''; $question = Question::findOrFail($id); if(empty($this->user) or $question->user_id != $this->user->id){ \DB::table('yiiquestions')->increment('views');//счетчик просмотров }else{ $s = Subscribe::where('question_id', '=', $question->id)->where('user_id', '=', $this->user->id)->get(); } return view('questions.show',[ 'question' => $question, 's' => $s, 'answers' => Answer::where('question_id','=',$question->id)->with('user')->get() ]); }catch(ModelNotFoundException $e){ return view('errors.404'); } }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); $Role1 = \App\Models\Role::create(['title' => 'Пользователь', 'default' => true]); $Role2 = \App\Models\Role::create(['title' => 'Администратор', 'admin' => true]); \App\Models\Group::create(['title' => 'КИТ-10']); $Group1 = \App\Models\Group::create(['title' => 'КИТ-10']); \App\Models\Group::create(['title' => 'КИТ-20']); $Group2 = \App\Models\Group::create(['title' => 'КИТ-30']); \App\Models\Group::create(['title' => 'КИТ-40']); \App\User::create(['first_name' => 'Admin', 'last_name' => 'Admin', 'second_name' => 'Admin', 'email' => '*****@*****.**', 'password' => bcrypt('admin'), 'group_id' => $Group2->id, 'role_id' => $Role2->id]); \App\User::create(['first_name' => 'Test first name', 'last_name' => 'Test last name', 'second_name' => 'Test second name', 'email' => '*****@*****.**', 'password' => bcrypt('123456'), 'group_id' => $Group1->id, 'role_id' => $Role1->id]); \Illuminate\Support\Facades\DB::table('type_question')->insert([['title' => 'radio'], ['title' => 'checkbox']]); $Prototype = \App\Models\Prototype::create(['title' => 'Тест по биологии', 'time' => 40, 'count_questions' => 5]); $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Сколько лап у ежа?', 'type' => 'radio']); $Answer = \App\Models\Answer::create(['text' => '4', 'right' => true, 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => '6', 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => 'Много', 'question_id' => $Question->id]); $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какая длина хобота у слона?', 'type' => 'radio']); $Answer = \App\Models\Answer::create(['text' => 'У слона нет хобота', 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => '2 метра', 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => 'Зависит от возраста', 'right' => true, 'question_id' => $Question->id]); $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Сколько рёбер у человека?', 'type' => 'radio']); $Answer = \App\Models\Answer::create(['text' => '12 пар', 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => 'Кто такой человек?', 'right' => true, 'question_id' => $Question->id]); $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какие типы данных из перечисленных есть в PHP?', 'type' => 'checkbox']); $Answer = \App\Models\Answer::create(['text' => 'Integer', 'right' => true, 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => 'Float', 'right' => true, 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => 'String', 'right' => true, 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => 'Char', 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => 'Array', 'right' => true, 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => 'Callbacks / Callables', 'right' => true, 'question_id' => $Question->id]); $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какой оператор выполняет строгое сравнение?', 'type' => 'radio']); $Answer = \App\Models\Answer::create(['text' => '==', 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => '===', 'right' => true, 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => '&', 'question_id' => $Question->id]); $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какой оператор не правильный?', 'type' => 'radio']); $Answer = \App\Models\Answer::create(['text' => '$a and $b', 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => '$a or $b', 'right' => true, 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => '! $a', 'right' => true, 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => '$a => $b', 'right' => true, 'question_id' => $Question->id]); $Answer = \App\Models\Answer::create(['text' => '$a <= $b', 'right' => true, 'question_id' => $Question->id]); // $this->call('UserTableSeeder'); }
public function actionIndex() { if (\Yii::$app->user->isGuest) { $this->redirect(array("login")); } else { $exam = Exam::find()->where("1=1")->one(); // modify later if (Yii::$app->request->post()) { $post = Yii::$app->request->post(); $answers = $post["Answers"]; $transaction = Yii::$app->db->beginTransaction(); try { $userscore = new UserScore(); $userscore->finished_time = date("Y-m-d H:i:s"); $userscore->user_id = Yii::$app->user->identity->id; $userscore->exam_id = $exam->id; $userscore->score = 0; $userAnswers = []; $totalScore = 0; foreach ($exam->getQuestions()->all() as $question) { $userAnswer = new UserHasAnswer(); $userAnswer->user_id = Yii::$app->user->identity->id; $userAnswer->answer_id = $answers[$question->id]; $userAnswer->exam_id = $exam->id; $userAnswer->save(); $correctAnswer = Answer::find()->where("is_correct=:is_correct AND question_id=:question_id", [":is_correct" => 1, ":question_id" => $question->id])->one(); if ($userAnswer->answer_id === $correctAnswer->id) { $userscore->score += $question->score; } $totalScore += $question->score; $userAnswers[] = $userAnswer; } $userAnswer->save(); $transaction->commit(); // $this->redirect(["showScore"], ["userAnswers" => $userAnswers, "userScore" => $userscore]); return $this->render("score_summary", ["userAnswers" => $userAnswers, "userScore" => $userscore, "totalScore" => $totalScore]); } catch (Exception $exc) { $transaction->rollBack(); Yii::$app->session->setFlash("error", $exc->getTraceAsString()); } } return $this->render('index', ["exam" => $exam]); } }
public function store(Quiz $quiz, Request $request) { $student_id = Auth::user()->student()->first()->id; if (Score::whereQuizIdAndStudentId($quiz->id, $student_id)) { return "e"; } $points = 0; foreach ($request->all() as $r) { $ca = CorrectAnswer::whereQuestionId($r['question_id'])->first()->option_id; if ($ca == $r['option_id']) { $points++; } if (!Answer::whereStudentIdAndQuestionId($student_id, $r['question_id'])->first()) { Answer::create(['student_id' => $student_id, 'question_id' => $r['question_id'], 'option_id' => $r['option_id']]); } } $score = Score::create(['score' => $points, 'time' => time() - strtotime($quiz->date_time), 'quiz_id' => $quiz->id, 'student_id' => $student_id]); DB::table('quiz_student')->insert(['student_id' => $student_id, 'quiz_id' => $quiz->id]); return $score; }
/** * Register any other events for your application. * * @param \Illuminate\Contracts\Events\Dispatcher $events * @return void */ public function boot(DispatcherContract $events) { parent::boot($events); Question::deleting(function ($Question) { // Deleted all answers for this question foreach ($Question->answers as $Answer) { $Answer->delete(); } }); Question::restoring(function ($Question) { // Restored all answer for this foreach ($Question->answers()->withTrashed()->get() as $Answer) { $Answer->restore(); } }); Prototype::deleting(function ($Prototype) { // Deleted all questions for this foreach ($Prototype->questions as $Question) { $Question->delete(); } }); Prototype::restoring(function ($Prototype) { // Restored all question for this foreach ($Prototype->questions as $Question) { $Question->restore(); } }); User::deleting(function ($User) { // Deleted all assigners this user foreach ($User->assigners as $Assigner) { $Assigner->delete(); } }); Answer::deleting(function ($Answer) { // Deleting image if ($Answer->image) { unlink($Answer->image); } }); }
/** * @return \yii\db\ActiveQuery */ public function getAnswers() { return $this->hasMany(Answer::className(), ['question_id' => 'id']); }
/** * Finds the Answer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Answer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Answer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getAnswers() { return $this->hasMany(Answer::className(), ['id' => 'answer_id'])->viaTable('user_has_answer', ['user_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getIdAnswer() { return $this->hasOne(Answer::className(), ['id' => 'id_answer']); }
/** * @return mixed */ public function getTrue($questionId) { return Answer::where('correct', 1)->where('question_id', $questionId)->first(); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(Requests\Admin\Questions\Store $request, Question $Question) { $Question->fill($request->input('question')); $Question->save(); if ($request->hasFile('image') && $request->file('image')->isValid()) { $QuestionImage = $request->file('image'); $QuestionImage = $QuestionImage->move('upload\\questions', $Question->id . '.' . $QuestionImage->getClientOriginalExtension()); $Question->image = $QuestionImage->getPathname(); $Question->save(); } elseif ($request->has('question.delete_image') && $request->input('question.delete_image') == 'on') { $Question->image = null; $Question->save(); } $IdsAnswers = []; foreach ($request->input('answers') as $key => $answer) { $Answer = Answer::findOrNew($request->input('answers.' . $key . '.id')); $Answer->fill(['text' => $request->input('answers.' . $key . '.text'), 'right' => $request->input('answers.' . $key . '.right', false), 'question_id' => $Question->id]); $Answer->save(); $IdsAnswers[] = $Answer->id; if ($request->hasFile('answers.' . $key . '.image') && $request->file('answers.' . $key . '.image')->isValid()) { $AnswerFile = $request->file('answers.' . $key . '.image'); $AnswerFile = $AnswerFile->move('upload\\answers', $Answer->id . '.' . $AnswerFile->getClientOriginalExtension()); $Answer->image = $AnswerFile->getPathname(); $Answer->save(); } elseif ($request->has('answers.' . $key . '.delete_image') && $request->input('answers.' . $key . '.delete_image') == 'on') { $Answer->image = null; $Answer->save(); } } $AnswersForDeleting = $Question->answers()->whereNotIn('id', $IdsAnswers)->get(); if ($AnswersForDeleting->count()) { foreach ($AnswersForDeleting as $Answer) { $Answer->delete(); } } return redirect()->back(); }
</div> <div class="panel-body"> <span>[最新回答] <?php echo empty(Answer::replyLatest($question->id)->content) ? '暂无' : Answer::replyLatest($question->id)->content?></span> <a href="/course/qadetail?qid=<?php echo $question->id?>"><span class="fa fa-comments comment-down"><?php echo count(Answer::replyList($question->id))?></span></a> <a href="/course/qadetail?qid=<?php echo $question->id?>"><span class="fa fa-eye comment-up"><?php echo $question->views?></span></a> </div> </div> <?php endforeach ?> <?php else: ?> <div class="alert alert-warning" role="alert"><?php echo Yii::t('app', 'No more questions.');?></div> <?php endif ?> </section> <section id="section-reply"> <?php if (Answer::myReplyList($user->id)): ?> <?php foreach (Answer::myReplyList($user->id) as $reply): ?> <div class="alert alert-success" role="alert"> <span>[回复<a href="#"><?php echo User::findModel($reply->answered_user_id)->username?>]</a>:<?php echo $reply->content?></span> <a href="/course/qadetail?qid=<?php echo $reply->question_id?>"><span class="fa fa-eye" style="float: right;margin-left: 5px"></span></a> <span class="zone-reply-time"><?php echo Common::getAwayTime($reply->create_time)?></span> </div> <?php endforeach ?> <?php else: ?> <div class="alert alert-warning" role="alert"><?php echo Yii::t('app', 'No more answers.');?></div> <?php endif ?> </section> <section id="section-focus"> <div class="alert alert-warning" role="alert"><?php echo Yii::t('app', 'No more focus questions.');?></div> </section> </div> </div>
/** * @return \yii\db\ActiveQuery */ public function getAnswer() { return $this->hasOne(Answer::className(), ['id' => 'answer_id']); }
<div class="media-body"> <span class="fa fa-question-circle fa-lg col-lg-1 qa-question-fa"></span> <span class="media-heading qa-content" ><?php echo Markdown::convert($question->content)?></span> <div class="qa-new"> <span class="fa fa-comment fa-lg col-lg-1"></span> <?php if (Answer::replyLatest($question->id)): ?> <span>[最新回答]</span> <span><a href=""><?php echo User::findModel(Answer::replyLatest($question->id)->answer_user_id)->username?> :</a></span> <span><?php echo Answer::replyLatest($question->id)->content?></span> <?php else: ?> <span>[还没有人回答]</span> <?php endif ?> </div> <span class="evaluation-time col-lg-4">时间:<?php echo Common::getAwayTime($question->create_time)?></span> <a href="/course/qadetail?qid=<?php echo $question->id?>"><span class="fa fa-comments comment-down"><?php echo count(Answer::replyList($question->id))?></span></a> <a href="/course/qadetail?qid=<?php echo $question->id?>"><span class="fa fa-eye comment-up"><?php echo $question->views?></span></a> </div> </div> <?php endforeach ?> </div> </div> <div class="tab-pane" id="attachment" style="margin-top:20px"> <div class="container row"> <table class="table table-striped"> <?php if ($attachments): ?> <?php foreach ($attachments as $attachment): ?> <tr class="info"> <td><?php echo $attachment->name . '.' . $attachment->extension?></td> <td><a href="/resource/download?id=<?php echo $attachment->id;?>" style="cursor:pointer"><span class="fa fa-download"></span></a></td> </tr>
<div class="panel-heading"> <a class="panel-title" href="#">热门问答</a> </div> <?php if ($hotAsk) { foreach ($hotAsk as $h) { ?> <div class="col-sm-12 mt0"> <div class="media-heading"> <?php echo html::a($h['title'], ['/main/view', 'id' => $h['id']], ['title' => $h['title']]); ?> <i class="fa fa-trophy excellent"></i> <?php echo html::tag('span', Answer::getCountById($h['id']), ['class' => 'badge badge-reply-count']), '回答'; ?> </div> </div> <?php } } ?> </div> <h1><?php echo Html::encode($this->title); ?> </h1> <div> <?php
public function saveAnswer(Request $request) { if ($request->input('is_test') != 1) { $applicant = Applicant::where('form_key', $request->input('form_key'))->first(); $blueprint = Blueprint::find($applicant->blueprint_id); $question = Question::find($request->input('question_id')); $answer = Answer::firstOrCreate(["blueprint_id" => $blueprint->id, "question_id" => $question->id, "form_key" => $applicant->form_key]); if ($question->type == "integer" || $question->type == "number") { $answer->num_value = $request->input('question_value'); $answer->text_value = null; } else { $answer->num_value = null; $answer->text_value = $request->input('question_value'); } $answer->update(); $answer->question_value = $request->input('question_value'); $answer->new_token = csrf_token(); } else { $question = Question::find($request->input('question_id')); $answer = new Answer(["blueprint_id" => $question->blueprint->id, "question_id" => $question->id, "form_key" => "xxx"]); $answer->num_value = $question->type == "number" ? $request->input('question_value') : null; $answer->text_value = $question->type != "number" ? $request->input('question_value') : null; $answer->question = $question; //$answer->update(); $answer->question_value = $request->input('question_value'); $answer->new_token = csrf_token(); } return response()->json($answer)->header('Access-Control-Allow-Origin', '*'); }
public function actionAddAnswer() { $questionId = Yii::$app->request->post('questionId'); $content = Yii::$app->request->post('content'); $answeredUserId = Yii::$app->request->post('answeredUserId'); $answerUserId = Yii::$app->user->id; $model = new Answer(); if ($model->addData($questionId, $content, $answerUserId, $answeredUserId)) { echo Json::encode('true'); return; } else { echo Json::encode('false'); return; } }
public function getRightAnswer() { $query = 'question_answer.is_right=1 AND question_answer.question_id=' . $this->id; return $this->hasMany(Answer::className(), ['id' => 'answer_id'])->viaTable('question_answer', ['question_id' => 'id'])->innerJoin('question_answer', 'answer.id=question_answer.answer_id')->where($query); }
<?php use app\models\Question; use app\models\Answer; $question = array_column(Question::find()->select(['id'])->asArray()->all(), 'id'); $answer = array_column(Answer::find()->select(['id'])->asArray()->all(), 'id'); $boolean = [0, 1]; return ['question_id' => $faker->randomElement($question), 'answer_id' => $faker->randomElement($answer), 'is_right' => $faker->randomElement($boolean)];