Пример #1
0
 public function storequestion(Request $request)
 {
     //
     $rules = ['issue_id' => 'required', 'sendDate' => 'required', 'question' => 'required'];
     $this->validate($request, $rules);
     $issue = Issue::findOrFail($request->get('issue_id'));
     $issue->status = "等待回覆";
     $issue->save();
     $project = Project::findOrFail($issue->project_id);
     foreach ($request->get('sendList') as &$receiver) {
         if (empty($sendList)) {
             if ($receiver == '業務') {
                 $target_id = $project->salesman;
             } elseif ($receiver == '業務主管') {
                 $target = User::where('job', '業務主管')->firstOrFail();
                 $target_id = $target->id;
             } elseif ($receiver == '產品專員') {
                 $target = User::where('job', '產品專員')->firstOrFail();
                 $target_id = $target->id;
             } elseif ($receiver == '總經理') {
                 $target = User::where('job', '總經理')->firstOrFail();
                 $target_id = $target->id;
             }
             $sendList = $target_id;
         } else {
             if ($receiver == '業務') {
                 $target_id = $project->salesman;
             } elseif ($receiver == '業務主管') {
                 $target = User::where('job', '業務主管')->firstOrFail();
                 $target_id = $target->id;
             } elseif ($receiver == '產品專員') {
                 $target = User::where('job', '產品專員')->firstOrFail();
                 $target_id = $target->id;
             } elseif ($receiver == '總經理') {
                 $target = User::where('job', '總經理')->firstOrFail();
                 $target_id = $target->id;
             }
             $sendList = $sendList . "|" . $target_id;
         }
     }
     $question = new Question(array('question' => $request->get('question'), 'sendDate' => $request->get('sendDate'), 'sendList' => $sendList, 'status' => '等待回覆'));
     $question->issue()->associate($issue);
     $sender = User::find(\Auth::id());
     $question->sender()->associate($sender);
     $question->save();
     return \Redirect::to('issue/show/' . $issue->id)->with('message', 'Your Issue has been updated!');
 }