public function searchTags() { $str = Input::get('q'); $id = Input::get('id'); if ($str != "") { $items = Tag::where('text', 'LIKE', '%' . $str . '%')->get(); $total_count = $items->count(); if ($total_count !== 0) { return response()->json(['items' => $items, 'total_count' => $total_count]); } } elseif ($id > 0) { $items = Taggable::where('taggable_id', $id)->get(); $return_arr = array(); $row_array = array(); foreach ($items as $item) { $tag = Tag::where('id', $item->tag_id)->first(); $row_array['id'] = $tag['id']; $row_array['text'] = $tag['text']; array_push($return_arr, $row_array); } echo json_encode($return_arr); } }
public function taggables() { return Taggable::where('tag_id', '=', $this->id)->get(); }