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');
 }
 public function putDeleteAction($id)
 {
     $note = Note::findOrFail($id);
     if ($this->method == 'PUT') {
         $note->title = $this->post_data['title'];
         $note->user_id = $this->authed->id;
         $note->save();
         return $this->json($note->toArray());
     }
     if ($this->method == 'DELETE') {
         try {
             $note->delete();
         } catch (\Exception $e) {
             return $this->json(['status' => 0]);
         }
         return $this->json(['status' => 1]);
     }
     if ($this->method == 'GET') {
         $notes = Note::where('user_id', '=', $this->authed->id)->where('id', '=', $id)->select('title', 'id', 'updated')->get()->toArray();
         foreach ($notes as &$n) {
             $count = Task::where('note_id', '=', $id)->count('id');
             $n['count_task'] = $count;
             $n['tasks'] = Task::where('note_id', '=', $id)->get()->toArray();
             // dump($n['tasks']);
             // dump($notes);
             //fix tag ??
             $tag_id = array();
             foreach ($n['tasks'] as &$key) {
                 $tag_id = $tag_id = Tag_has_task::where('task_id', '=', $key['id'])->select('tag_id')->get();
                 foreach ($tag_id as &$tag_id) {
                     $tag_id['count_tag'] = Tag::where('id', '=', $tag_id['tag_id'])->count('id');
                     $tag_id['tag'] = Tag::where('id', '=', $tag_id['tag_id'])->get()->toArray();
                 }
                 $key['count_tag'] = $tag_id['count_tag'];
                 $key['tag'] = $tag_id['tag'];
             }
         }
         return $this->json($notes);
     }
     return $this->fail('F*****g fail');
 }