public function index(Request $request) { if ($request->input('search_str')) { $search_str = Input::get('search_str'); $search_string = explode(" ", $search_str); $keywords = array(); foreach ($search_string as $str) { array_push($keywords, $str); } $questions_ = new Questions(); $all_questions = $questions_->search_questions($search_str); $tag_ = new Tags(); $find_and_get_tag_ids = $tag_->find_and_get_tag_ids($keywords); $tag_ids = array(); if (!empty($find_and_get_tag_ids)) { foreach ($find_and_get_tag_ids as $tags) { array_push($tag_ids, $tags['id']); } } $question_tag = new Question_Tag(); $questions = $question_tag->get_question_ids_by_tag_ids($tag_ids); $sorted_questions_ids = array(); if (!empty($questions)) { foreach ($questions as $question) { array_push($sorted_questions_ids, $question['question_id']); } } //print_r($sorted_questions_ids); // die; $all_questions1 = $questions_->get_all_questions_where_in($sorted_questions_ids); // print_r($all_questions->toArray()); // die; } else { $questions = new Questions(); $all_questions = $questions->get_all_questions()->toArray(); // print_r($all_questions); // die; } // print_r($all_questions); // die; $cat = new Category(); $root_category = array(); $root_categories = $cat->get_categories_by_parent_id(0); if (!empty($root_categories)) { foreach ($root_categories as $category) { array_push($root_category, $category['title']); } } // print_r($all_questions); // die; return view('user/index')->withAllQuestions($all_questions)->withRootCategories($root_categories); }