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


PHP Question::find方法代码示例

本文整理汇总了PHP中app\Question::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::find方法的具体用法?PHP Question::find怎么用?PHP Question::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Question的用法示例。


在下文中一共展示了Question::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setNotanswered

 /**
  * Setting question to not answered, if question wasnt answered.
  *
  * @return Response
  */
 public function setNotanswered($id)
 {
     $question = \App\Question::find($id);
     $question->status = "notanswered";
     $question->save();
     return redirect()->to('moderator');
 }
开发者ID:nara-l,项目名称:quizer,代码行数:12,代码来源:ModeratorController.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $user = JWTAuth::parseToken()->authenticate();
     $user_id = $user->id;
     $question = Question::find($request['question_id']);
     if (!$question) {
         return response()->json(['success' => false, 'message' => "invalid question id."]);
     }
     $question_owner = $question->owner();
     //        dd($question_owner);
     if ($user->points == 0) {
         return response()->json(['success' => false, 'message' => "Please recharge"]);
     }
     //validate data
     $validator = Validator::make($request->all(), array('text' => 'required', 'question_id' => 'required'));
     if ($validator->fails()) {
         return $validator->errors()->all();
     } else {
         $previousAnswer = Answer::where('question_id', $request['question_id'])->where('user_id', $user_id)->get();
         if (count($previousAnswer) > 0) {
             return response()->json(['success' => false, 'message' => "You've already answered this question before.", 'answer' => $request['text']]);
         } else {
             $follower_user = $user->id . "_" . $question_owner->id;
             Answer::create(['text' => $request['text'], 'user_id' => $user_id, 'question_id' => $request['question_id'], 'follower_user' => $follower_user]);
             try {
                 $user->addFollowing($question_owner);
                 $user->points = $user->points - 1;
                 $user->save();
             } catch (Exception $e) {
             }
         }
         return response()->json(['success' => true, 'message' => "Answer Added Successfully", 'answer' => $request['text']]);
     }
 }
开发者ID:jubaedprince,项目名称:nohunchAPI,代码行数:40,代码来源:AnswerController.php

示例3: storeTranscription

 public function storeTranscription($surveyId, $questionId, Request $request)
 {
     $callSid = $request->input('CallSid');
     $question = Question::find($questionId);
     $questionResponse = $question->responses()->where('session_sid', $callSid)->firstOrFail();
     $questionResponse->responseTranscription()->create(['transcription' => $this->_transcriptionMessageIfCompleted($request)]);
 }
开发者ID:TwilioDevEd,项目名称:automated-survey-laravel,代码行数:7,代码来源:QuestionResponseController.php

示例4: delete_item

 public function delete_item($q_id)
 {
     $q = Question::find($q_id);
     $this->authorize('qna-edit', $q);
     $q->delete();
     return redirect('qs');
 }
开发者ID:smartbos,项目名称:qna,代码行数:7,代码来源:QController.php

示例5: store

 public function store($questionId)
 {
     $answer = Request::user()->answers()->create(['answer' => Request::input('answer')]);
     $question = Question::find($questionId);
     $question->answers()->save($answer);
     return redirect()->back();
 }
开发者ID:jubaedprince,项目名称:incuba_php,代码行数:7,代码来源:QuestionsAnswersController.php

示例6: proposeSolution

 public function proposeSolution()
 {
     $questionId = Request::get('questionId');
     $question = Question::find($questionId);
     $answers = $question->answers()->get()->toArray();
     // Prepare array of proposed answers
     $proposedSolution = [];
     if ($question->question_type == 'one_variant') {
         $proposedSolution[] = (int) Request::get('chosenAnswer');
     } else {
         $proposedSolution = Request::get('chosenAnswers');
     }
     // Prepare array of correct answers
     $correctSolution = [];
     foreach ($answers as $answer) {
         if ($answer['is_correct']) {
             $correctSolution[] = $answer['id'];
         }
     }
     $proposedSolutionResult = $proposedSolution == $correctSolution;
     // pass to response detailed results on proposed solution
     $proposedSolutionWithDetailedResult = [];
     foreach ($proposedSolution as $answerId) {
         foreach ($answers as $answer) {
             if ($answer['id'] == $answerId) {
                 $is_correct = $answer['is_correct'];
             }
         }
         $proposedSolutionWithDetailedResult[$answerId] = $is_correct;
     }
     if (\Auth::user()) {
         \Auth::user()->replies()->updateOrCreate(['question_id' => $questionId], ['is_correct' => $proposedSolutionResult]);
     }
     return response()->json(['correctSolution' => $correctSolution, 'proposedSolutionWithDetailedResult' => $proposedSolutionWithDetailedResult, 'proposedSolutionResult' => $proposedSolutionResult]);
 }
开发者ID:sjardim,项目名称:GA-Exam,代码行数:35,代码来源:QuizController.php

示例7: store

 /**
  * Store a newly created resource in storage.
  * Assumption: All quesitons are multi-value,
  *      Questions are in the database already
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $scoreCard = session('score_card');
     if (Question::find($request->qID)->type == 'free-response') {
         $free_response;
         $question = Question::find($request->qID);
         if ($scoreCard->responses()->where('question_id', $question->id)->count() >= 1) {
             $free_response_id = $scoreCard->responses()->where('question_id', $question->id)->first()->id;
             $free_response = FreeResponse::find($free_response_id);
         } else {
             $free_response = new FreeResponse();
         }
         $free_response->question_id = $request->qID;
         $free_response->response = $request->response;
         $free_response->score_card_id = $scoreCard->id;
         $free_response->save();
         $scoreCard->responses()->save($free_response);
     } else {
         $answers = $scoreCard->answer_questions()->wherePivot('question_id', '=', $request->qID)->get();
         $student_response = $scoreCard->questions()->where('questions.id', '=', $request->qID)->get();
         $studentAnswers = array();
         foreach (Question::find($request->qID)->answers()->get() as $a) {
             if ($request->has('cb' . $a->pivot->id)) {
                 array_push($studentAnswers, $a->pivot->id);
             }
         }
         if (count($studentAnswers) > 0) {
             // echo "detaching...<br>";
             $scoreCard->questions()->detach($request->qID);
             foreach ($studentAnswers as $a) {
                 // echo "attaching...".$a."<br>";
                 $scoreCard->questions()->attach($request->qID, array('answer_question_id' => $a));
             }
         } else {
             $scoreCard->questions()->detach($request->qID);
             $scoreCard->questions()->attach($request->qID, array('answer_question_id' => null));
         }
     }
     if ($request->has('next')) {
         $question = $scoreCard->next();
         if ($question != null) {
             $questionNumber = $request->session()->get('questionNumber');
             $questionNumber++;
             $request->session()->put('questionNumber', $questionNumber);
             return $this->goto_qustion($question, $scoreCard);
         } else {
             return redirect('/finished_quiz');
         }
     }
     if ($request->has('prev')) {
         $question = $scoreCard->prev();
         if ($question != null) {
             $questionNumber = $request->session()->get('questionNumber');
             $questionNumber--;
             $request->session()->put('questionNumber', $questionNumber);
             return $this->goto_qustion($question, $scoreCard);
         }
     }
 }
开发者ID:sgomez118,项目名称:ASM-Software-Management,代码行数:66,代码来源:ScoreCardController.php

示例8: postQuestionEdit

 /**
  * Responds to request to POST /question/edit/{question_id}
  */
 public function postQuestionEdit($question_id, Request $request)
 {
     $this->validate($request, ['question' => 'required|min:5']);
     $question = Question::find($question_id);
     $question->question = $request->question;
     $question->save();
     return redirect('/edit/' . $question->quiz_id . '#question' . $question_id);
 }
开发者ID:philipjamesk,项目名称:p4,代码行数:11,代码来源:QuestionController.php

示例9: _questionAfter

 private function _questionAfter($questionId)
 {
     $question = \App\Question::find($questionId);
     $survey = \App\Survey::find($question->survey_id);
     $allQuestions = $survey->questions()->orderBy('id', 'asc')->get();
     $position = $allQuestions->search($question);
     $nextQuestion = $allQuestions->get($position + 1);
     return $this->_idIfNotNull($nextQuestion);
 }
开发者ID:illuminate3,项目名称:automated-survey-laravel,代码行数:9,代码来源:QuestionResponseController.php

示例10: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $user = $request->user();
     $question = Question::find($request->id);
     if ($user && $user->id === $question->user_id) {
         return $next($request);
     }
     return redirect()->back();
 }
开发者ID:samchurney,项目名称:teacherspet,代码行数:16,代码来源:mustBeOwner.php

示例11: reply

 public function reply()
 {
     $questionId = Request::get('questionId');
     $chosenAnswerId = Request::get('chosenAnswerId');
     $replyResult = Answer::findOrFail($chosenAnswerId)->is_correct;
     \Auth::user()->replies()->updateOrCreate(['question_id' => $questionId], ['is_correct' => $replyResult]);
     $answers = Question::find($questionId)->answers();
     $correctAnswerId = $answers->where('is_correct', '=', true)->first()->id;
     return response()->json(['correctAnswerId' => $correctAnswerId, 'chosenAnswerId' => $chosenAnswerId, 'replyResult' => $replyResult, 'answers' => $answers->get()]);
 }
开发者ID:phpclub,项目名称:GA-Exam,代码行数:10,代码来源:QuizController.php

示例12: 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.');
 }
开发者ID:herzcthu,项目名称:Laravel-HS,代码行数:18,代码来源:EloquentQuestionRepository.php

示例13: 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)
 {
     //
     $q = Question::find($id);
     if (!$q) {
         return response()->json(array('msg' => 'Not found'), 404);
     }
     if ($q->update($request->all())) {
         return response()->json($q);
     }
     return response()->json(array('msg' => 'Update faild'), 400);
 }
开发者ID:EManual,项目名称:interview,代码行数:19,代码来源:QuestionController.php

示例14: questionDel

 public function questionDel(Request $request)
 {
     Question::find($request->get('id'))->delete();
     Question::where('subId', $request->get('id'))->delete();
     $log = new Log();
     $log->memberId = Auth::user()->id;
     $log->detail = 'Delete Post,' . $request->get('id');
     $log->save();
     if ($request->get('redirect') == '') {
         return redirect(route('home'));
     } else {
         return redirect(html_entity_decode($request->get('redirect')));
     }
 }
开发者ID:komphet5139,项目名称:ubr,代码行数:14,代码来源:Home.php

示例15: destroy

 /**
  * Delete a question
  * @param Request $request
  * @param $id
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function destroy(Request $request, $id)
 {
     $event = Event::find($request->input('event'));
     $question = Question::find($id);
     if ($question && $event->user_id == $request->user()->id) {
         $question->delete();
         //Flash a message to the user
         \Flash::success('Question deleted');
     } else {
         //Flash a message to the user
         \Flash::danger('Sorry, permission denied');
     }
     //Redirect back to the admin page
     //return redirect(action('EventsController@admin', $request->input('event')));
     return Redirect::back()->with(['tabName' => 'questions']);
 }
开发者ID:rachelglover,项目名称:entries,代码行数:22,代码来源:QuestionController.php


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