コード例 #1
0
 public function update(Request $request, $id)
 {
     // dd('a//sfsaf');
     if ($request->isMethod('get')) {
         $this->data['roles'] = $this->getRoles();
         $this->data['types'] = $this->getTypes();
         $this->data['items'] = Question::get();
         $this->data['old'] = Question::find($id);
         if ($this->data['old']) {
             return view('pages.question.update', $this->data);
         } else {
             return redirect('question');
         }
     } elseif ($request->isMethod('post')) {
         $row = Question::find($id);
         $row->update($request->all());
         return redirect('question/detail/' . $id);
     }
 }
コード例 #2
0
ファイル: EventController.php プロジェクト: bilfash/monstaff
 public function question(Request $request, $id)
 {
     if ($request->isMethod('get')) {
         $this->data['items'] = Pivot::where('eventid', $id)->where('deleted_at', null)->get();
         $this->data['questions'] = Question::get();
         return view('pages.event.question', $this->data);
     } else {
         // dd($request->all());
         $data = $request->all();
         $event = Event::find($id);
         if ($event) {
             if (array_key_exists('delete', $data)) {
                 foreach ($data['delete'] as $key => $value) {
                     $item = Pivot::find($value);
                     $item->delete();
                 }
             }
             if (array_key_exists('pivot', $data)) {
                 foreach ($data['pivot'] as $key => $value) {
                     $item = new Pivot();
                     $item->eventid = $id;
                     $item->questionid = $value;
                     $item->save();
                 }
             }
         }
         return redirect('event/detail/' . $id);
     }
 }