本文整理汇总了PHP中app\Question::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::with方法的具体用法?PHP Question::with怎么用?PHP Question::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Question
的用法示例。
在下文中一共展示了Question::with方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: question
public function question()
{
$user = \Auth::user();
$isAjax = \Request::ajax();
$correct_answers = $user->correct_answers;
if (!$isAjax && $correct_answers >= 3) {
Redirect::to('user/start');
}
$data = Question::select('title')->get();
$value = Session::get('index');
if ($value >= count($data) || !$value) {
$value = 1;
}
if ($isAjax) {
Session::set('index', $value + 1);
$value = Session::get('index');
}
$question = \App\Question::with(array('answers' => function ($query) {
$query->select("id", "title", "question_id");
}))->select('id', 'title')->findOrFail($value);
$question['correct_answers'] = $correct_answers;
if ($isAjax) {
return json_encode($question);
}
return view('auth.question', compact('question'));
}
示例2: getQuestionDelete
/**
* Responds to request to GET /question/delete/{question_id}
*/
public function getQuestionDelete($question_id)
{
$question = Question::with('quiz')->find($question_id);
// store quiz_id for redirect
$quiz_id = $question->quiz->id;
$question->delete();
return redirect('/edit/' . $quiz_id);
}
示例3: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index(Request $request)
{
if ($request->has('filterBy')) {
$questions = Question::with('state')->where($request->get('filterBy') . '_id', $request->get('id'))->get();
} else {
$questions = Question::orderBy('likes', 'desc')->with('state')->get();
}
$states = State::lists('name', 'id');
return view('admin.questions.index', compact('questions', 'states'));
}
示例4: findOrThrowException
/**
* @param $id
* @param bool $withOrganizations
* @return mixed
* @throws GeneralException
*/
public function findOrThrowException($id, $withProject = false)
{
if ($withProject) {
$question = Question::with('project')->find($id);
} else {
$question = Question::find($id);
}
if (!is_null($question)) {
return $question;
}
throw new GeneralException('That question does not exist.');
}
示例5: view
function get_item($q_id)
{
$q = Question::with('answers')->find($q_id);
return view('pages.item', ['q' => $q]);
}
示例6: showQuestion
public function showQuestion($slug)
{
$question = Question::with('user')->where('slug', $slug)->firstOrFail();
return view('questions.question', compact('question'));
}
示例7: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
return Question::with('answers')->findOrFail($id);
}
示例8: show
public function show($id)
{
$question = \App\Question::with('answers')->find($id);
return view('forum.question.show', compact('question'));
}
示例9: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$threads = Question::with('user')->orderBy('id', 'desc')->paginate(10);
//var_dump($threads);
return view('forum.index', compact('threads'));
}
示例10: forKnowledgeUnit
/**
* Get all of the questions for a given knowledge unit.
*
* @param Knowledge Unit $knowledgeunit_id
* @return Collection
*/
public function forKnowledgeUnit($knowledgeunit_id)
{
return Question::with("answers")->where('questions.knowledge_unit_id', $knowledgeunit_id)->orderBy('created_at', 'asc')->get();
}
示例11: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$question = Question::with(array('answers'))->findOrFail($id);
$request = $request->data;
$question->title = $request['title'];
for ($index = 0; $index < count($request['answers']); $index++) {
if ($index == $request['correct_answer_id']) {
$question->correct_answer_id = $question->answers[$index]->id;
}
$question->answers[$index]->title = $request['answers'][$index];
}
$question->answers()->saveMany($question->answers);
$question->save();
}
示例12: update
/**
* Receive answer from test and format next question and test
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$user = Auth::user();
$question = Question::with('skill')->with('difficulty')->with('skill.level')->with('skill.track')->find($request->question_id);
// log
$question->tests()->updateExistingPivot($request->test_id, ['answered' => TRUE], false);
$user->tested_questions()->attach($request->question_id, ['correct' => $correct = $question->correct_answer == $request->answer]);
// initialize
$error_limit = Config::get('mathtest.error_test');
$success_limit = Config::get('mathtest.success_test');
$difficulty = $question->difficulty_id;
$skill = $question->skill;
$level = $skill->level;
$track = $skill->track;
$test = Test::find($request->test_id);
$maxile = 0;
// track if user has done questions of the same skill and difficulty
$test_record = $test->questions()->selectRaw('question_test.question_id as id')->lists('id');
$total_correct = $user->numberCorrect()->where('questions.difficulty_id', '=', $difficulty)->where('questions.skill_id', '=', $skill->id)->take(max($error_limit, $success_limit))->first()->total_correct;
// dd($total_correct);
// dd($question->correct_answer == $request->answer);
$new_question = new Question();
// return $track->users()->get();
if ($correct) {
//if answer is correct
// dd($correct);
if ($total_correct < $success_limit - 1) {
//cleared this difficulty
if ($new_question = Question::similar($difficulty, $skill->id)->whereNotIn('id', $test_record)->first()) {
// dd($correct);
}
} else {
$user->track_results()->attach($question->track, ['difficulty_id' => $question->difficulty_id, 'skill_id' => $question->skill_id, 'level_id' => $question->skill->level->id, 'track_id' => $question->skill->track->id, 'maxile' => intval($question->skill->level->starting_maxile_level + 100 * ($difficulty / Difficulty::max('difficulty')) * ($skill->skill / Skill::whereLevelId($level->id)->max('skill')))]);
if ($difficulty < Difficulty::max('difficulty')) {
$new_question = Question::harder($difficulty, $skill->id)->whereNotIn('id', $test_record)->first();
} elseif ($skill->skill < Skill::whereTrackId($track->id)->whereLevelId($level->id)->max('skill')) {
$new_question = Question::whereNotIn('id', $test_record)->upskill($skill, $track->id, $level->id)->first();
} elseif ($level->level < Level::max('level')) {
$new_question = Question::whereNotIn('id', $test_record)->whereSkillId(Skill::orderBy('skill', 'asc')->first()->id)->first();
} else {
return ['msg' => 'You have reached the maximum level and difficulty for all skills in this track.'];
}
}
// if answer is wrong
} elseif ($difficulty > Difficulty::min('difficulty')) {
$new_question = Question::easier($difficulty, $skill->id)->whereNotIn('id', $test_record)->first();
} elseif ($skill->skill > Skill::whereTrackId($track->id)->whereLevelId($level->id)->min('skill')) {
$new_question = Question::whereNotIn('id', $test_record)->downskill($skill, $track->id, $level->id)->first();
} elseif ($level->level > Level::min('level')) {
$new_question = Question::whereNotIn('id', $test_record)->whereSkillId(Skill::orderBy('skill', 'desc')->first()->id)->first();
} else {
return ['msg' => 'You have reached the minimum level and difficulty for all skills in this track.'];
}
// dd($new_question);
if (isset($new_question) and $new_question->id != null) {
$new_question->tests()->attach($request->test_id, ['answered' => FALSE]);
return $this->formatQuiz($new_question, $request->test_id);
} else {
return ['result' => Track::join('track_user', 'id', '=', 'track_id')->where('track_user.user_id', '=', $user->id)->select('tracks.track')->selectRaw('max(track_user.maxile) as max')->groupBy('tracks.track')->get()];
}
}