示例#1
0
 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);
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $tag = Tag::all();
     return view('tags.index')->withTag($tag);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function tags()
 {
     $tags = Tag::all();
     return view('tags', ['tags' => $tags]);
 }
示例#4
0
 /**
  * Shows the questions tagged with $tag friendlyURL
  **/
 public function getTaggedWith($tag)
 {
     $tag = Tag::where('tagFriendly', $tag)->first();
     if ($tag) {
         return View::make('qa.index')->with('title', 'Questions Tagged with: ' . $tag->tag)->with('questions', $tag->questions()->with('users', 'tags', 'answers')->paginate(2));
     } else {
         return Redirect::route('index')->with('error', 'Tag not found');
     }
 }