当前位置: 首页>>代码示例>>PHP>>正文


PHP Question::findOrFail方法代码示例

本文整理汇总了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'));
 }
开发者ID:e-noumene,项目名称:Back,代码行数:13,代码来源:QuestionsController.php

示例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);
     });
 }
开发者ID:nilstr,项目名称:stackoverflow-clone,代码行数:33,代码来源:RouteServiceProvider.php

示例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();
 }
开发者ID:abalozz,项目名称:glaciar,代码行数:8,代码来源:QuestionsController.php

示例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();
 }
开发者ID:abalozz,项目名称:glaciar,代码行数:8,代码来源:QuestionVotesController.php

示例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'));
 }
开发者ID:jrafaelca,项目名称:school_virtual,代码行数:15,代码来源:AnswersController.php

示例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');
 }
开发者ID:kinnngg-lenz,项目名称:csacerc,代码行数:12,代码来源:QuestionsController.php

示例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();
 }
开发者ID:abalozz,项目名称:glaciar,代码行数:11,代码来源:AnswersController.php

示例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));
 }
开发者ID:kinnngg-lenz,项目名称:csacerc,代码行数:18,代码来源:LikesController.php

示例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);
 }
开发者ID:slipperydippery,项目名称:question,代码行数:17,代码来源:QuestionsController.php

示例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');
 }
开发者ID:EricChristensen,项目名称:Laravel-Millionaire,代码行数:15,代码来源:AnswersController.php

示例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;
 }
开发者ID:kinnngg-lenz,项目名称:csacerc,代码行数:22,代码来源:AnswerRequest.php

示例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');
 }
开发者ID:EricChristensen,项目名称:Laravel-Millionaire,代码行数:21,代码来源:GamesController.php

示例13: showQuestion

 public function showQuestion($id)
 {
     $question = Question::findOrFail($id);
     return view('member.forum.question', compact('question'));
 }
开发者ID:Panfen,项目名称:mango,代码行数:5,代码来源:ForumController.php

示例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);
 }
开发者ID:jrafaelca,项目名称:school_virtual,代码行数:14,代码来源:QuestionsController.php

示例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');
 }
开发者ID:samchurney,项目名称:teacherspet,代码行数:13,代码来源:QuestionController.php


注:本文中的app\Question::findOrFail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。