本文整理汇总了PHP中app\Question::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::findOrFail方法的具体用法?PHP Question::findOrFail怎么用?PHP Question::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Question
的用法示例。
在下文中一共展示了Question::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id, Request $request)
{
$question = Question::findOrFail($id);
$question->state_id = $request->get('state_id');
$question->save();
return redirect(route('admin.questions.index'));
}
示例2: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
//
parent::boot($router);
$router->bind('articles', function ($id) {
$article = Article::findOrFail($id);
// If the owner return all articles else return only published.
if (Auth::user() && $article->user_id === Auth::user()->id) {
$articles = Article::findOrFail($id);
} else {
$articles = Article::published()->findOrFail($id);
}
return $articles;
});
$router->bind('questions', function ($id) {
return Question::findOrFail($id);
});
$router->bind('answers', function ($id) {
return Answer::findOrFail($id);
});
$router->bind('tags', function ($name) {
return Tag::where('name', $name)->firstOrFail();
});
$router->bind('users', function ($id) {
return User::findOrFail($id);
});
}
示例3: update
public function update(QuestionRequest $request, $id)
{
$question = Question::findOrFail($id);
$this->authorize('edit-question', $question);
$question->fill($request->only(['title', 'body']))->save();
session()->flash('success', 'La pregunta ha sido editada.');
return redirect()->back();
}
示例4: destroy
public function destroy($id)
{
$question = Question::findOrFail($id);
if ($question->votes->contains(auth()->user())) {
$question->votes()->detach(auth()->user()->id);
}
return redirect()->back();
}
示例5: create
/**
* Show the form for creating a new resource.
*
* @param Request $request
* @return $this
*/
public function create(Request $request)
{
if ($request->has('question')) {
$questions = Question::findOrFail($request->get('question'))->unit->questions->lists('title', 'id');
} else {
$questions = Question::where('user_id', Auth::user()->id)->lists('title', 'id');
}
return view('teacher.answers.create')->with('questions', $questions)->with('title', trans('titles.create_new_answer'));
}
示例6: answer
/**
* @param $slug
*/
public function answer(AnswerRequest $request, $slug)
{
$question = $this->question->findOrFail($request->question_id);
$question->answer = $request->answer;
$question->save();
$request->user()->xp = $request->user()->xp + 20;
$request->user()->save();
return back()->withNotification("Success! Question has been answered.")->withType('success');
}
示例7: store
public function store(AnswerRequest $request)
{
$question = Question::findOrFail($request->input('question_id'));
$this->authorize('view-course', $question->course);
$answer = new Answer($request->only(['body']));
$answer->question()->associate($question);
$answer->user()->associate(auth()->user());
$answer->save();
session()->flash('success', 'La respuesta ha sido enviada.');
return redirect()->back();
}
示例8: likeQQ
/**
* Like post request handler for Questions
*
* @param $question_id
* @param Request $request
* @return mixed
*/
public function likeQQ($question_id, Request $request)
{
//Find Answer with Current Id;
$question = $this->question->findOrFail($question_id);
if (!$question->likes()->where('user_id', $request->user()->id)->get()->isEmpty()) {
$question->likes()->where('user_id', $request->user()->id)->first()->delete();
return back()->withNotification('Success! You unliked ' . str_limit($question->question, 50));
}
$question->likes()->create(['user_id' => $request->user()->id]);
return back()->withNotification('Success! You liked ' . str_limit($question->question, 50));
}
示例9: reorder
/**
* Dynamically reorder the display of questions through jquery's drag and drop with post
*
* @return Illuminate\Http\Response
*/
public function reorder()
{
$input = Input::get('order');
$i = 1;
foreach ($input as $order) {
$question = Question::findOrFail($order);
$question->order = $i;
$question->save();
$i++;
}
return Redirect::route('quests.show', $question->quest);
}
示例10: store
public function store(AnswerRequest $request)
{
$input = Request::all();
$new_answer = new Answer();
$new_answer->name = $input['name'];
$new_answer->more_info = $input['more_info'];
$correct = Request::only(['correct']);
$new_answer->correct = $correct['correct'];
if ($new_answer->correct == null) {
$new_answer->correct = 0;
}
$question = Question::findOrFail($input['question']);
$question->answers()->save($new_answer);
return redirect('answers/' . $question->id . '/manage');
}
示例11: authorize
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
$question = \App\Question::findOrFail($this->question_id);
if (!is_null($question->answer)) {
return false;
}
/**
* If question is asked globally then any admin can Answer
*/
if (is_null($question->for_user_id)) {
return $this->user()->isAdmin() ? true : false;
}
/**
* If User is Answerer
*/
return $this->user()->id == $question->for_user_id;
}
示例12: update
function update($id)
{
$game = Game::findOrFail($id);
$game->update(Request::all());
$input = Request::all();
//add questions
if (isset($input['add_questions'])) {
foreach ($input['add_questions'] as $question_id) {
$question = Question::findOrFail($question_id);
$game->questions()->save($question);
}
}
//remove questions
if (isset($input['remove_questions'])) {
foreach ($input['remove_questions'] as $question_id) {
$question = Question::findOrFail($question_id);
$game->questions()->detach($question);
}
}
return redirect('games');
}
示例13: showQuestion
public function showQuestion($id)
{
$question = Question::findOrFail($id);
return view('member.forum.question', compact('question'));
}
示例14: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$question = Question::findOrFail($id);
$question->delete();
$message = trans('messages.question_successfully_removed');
Flash::info($message);
return redirect()->route('teacher.units.show', $question->unit);
}
示例15: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$question = Question::findOrFail($id);
$question->delete();
Session::flash('flash_message', 'Task successfully deleted!');
return redirect()->action('QuestionController@index');
}