本文整理汇总了PHP中Question::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::with方法的具体用法?PHP Question::with怎么用?PHP Question::with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Question
的用法示例。
在下文中一共展示了Question::with方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$Q = Question::with('questionnaire')->find($id);
if (is_null($Q)) {
return Response::json(['error' => 'no such question found'], 404);
}
return Response::json($Q, 200);
}
示例2: postAdminEditQuestions
public function postAdminEditQuestions($question_id)
{
$question = Question::with('answers')->findOrFail($question_id);
$question->text = Input::get('question');
$question->correct_answer_id = Input::get('correct_answer');
foreach ($question->answers as $answer) {
$answer->text = Input::get('answers')[$answer->id];
$answer->save();
}
if ($question->save()) {
return Redirect::route('getAdminEditQuestions', $question_id)->with('success', 'You have edit question successfully.');
} else {
return Redirect::route('getAdminEditQuestions', $question_id)->with('fail', 'Error. Please try again later.');
}
}
示例3: questions
public function questions()
{
if (Auth::user()->correct_answers_count < 3) {
$result = Question::where('type', 0)->get();
} else {
if (Auth::user()->correct_answers_count == 3) {
$result = Question::where('type', 1)->get();
} else {
return Redirect::to('confirme');
}
}
$rand = rand(0, count($result) - 1);
$question = Question::with('answers')->find($result[$rand]->id);
return View::make('user.questions')->with('question', $question);
}
示例4: function
});
$app->get('/:id/questions', function ($id) use($app) {
$ids = explode(';', $id);
$questions = Question::whereIn('set_id', $ids)->get();
$questions->load('answers');
$res = $app->response();
$res['Content-Type'] = 'application/json';
$res->body($questions);
});
});
$app->group('/question(s)', function () use($app) {
$app->get('/', function () use($app) {
$questions = Question::with('answers')->get();
$res = $app->response();
$res['Content-Type'] = 'application/json';
$res->body($questions);
});
$app->get('/:id', function ($id) use($app) {
$question = Question::with('answers')->find($id);
$res = $app->response();
$res['Content-Type'] = 'application/json';
$res->body($question);
});
$app->get('/:id/answers', function ($id) use($app) {
$answers = Question::find($id)->answers;
$res = $app->response();
$res['Content-Type'] = 'application/json';
$res->body($answers);
});
});
$app->run();
示例5: getDetails
/**
* Details page
**/
public function getDetails($id, $title)
{
//First, let's try to find the question:
$question = Question::with('users', 'tags', 'answers')->find($id);
if ($question) {
//We should increase the "viewed" amount
$question->update(array('viewed' => $question->viewed + 1));
return View::make('qa.details')->with('title', $question->title)->with('question', $question);
} else {
return Redirect::route('index')->with('error', 'Question not found');
}
}