Ejemplo n.º 1
0
 public function putDeleteAction($id)
 {
     $task = Task::findOrFail($id);
     if ($this->method == 'PUT') {
         $task->content = $this->post_data['content'];
         $task->level = $this->post_data['level'];
         $task->status = $this->post_data['status'];
         $task->tag_id = $this->post_data['tag_id'];
         $task->note_id = $this->post_data['note_id'];
         $task->save();
         return $this->json($task->toArray());
     } elseif ($this->method == 'DELETE') {
         try {
             $has_task = Tag_has_task::where('task_id', '=', $id)->delete();
             $task->delete();
         } catch (\Exception $e) {
             return $this->json(['status' => 0]);
         }
         return $this->json(['status' => 1]);
     } elseif ($this->method == 'GET') {
         $tasks = Task::join('tag_has_task', 'task.id', '=', 'tag_has_task.task_id')->where('id', '=', $id)->get()->toArray();
         $tt_id = array();
         foreach ($tasks as &$t) {
             $tt_id = $t['tag_id'];
             $t['tag'] = Tag::where('id', '=', $t['tag_id'])->get()->toArray();
         }
         return $this->json($tasks);
     }
     return $this->fail('F*****g fail');
 }