/** * Displays the Search results page. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function getIndex(Request $request) { // check if request query parameters array is empty if (empty($request->all())) { // if most recently searched hashtag term exists, // then redirect to the search page for that term // otherwise, return the default search page $searched_term = \Session::get('searched_term'); if (isset($searched_term)) { $view = redirect('/search?term=' . $searched_term); } else { $view = view('search.index'); } } else { // validate request $this->validate($request, ['term' => 'required']); // parse request $term = strtolower(preg_replace('/\\s+/', '', $request->term)); // remove whitespace, convert to lowercase // save off hashtag term $this->saveHashtag($term); // get the social media posts for the specified hashtag term $posts = $this->getPosts($term); // get all the base sort function names for posts $posts_sort_by_names = Post::getSortFunctionNames(); // enable form for posts if a user is logged in $posts_enable_form = \Auth::check(); // return the search results page $view = view('search.index')->with(compact(['term', 'posts', 'posts_sort_by_names', 'posts_enable_form'])); } return $view; }
/** * Displays the Delete Posts page. * * @return \Illuminate\Http\Response */ public function getDelete() { // return the Delete Posts page with the user's saved posts and posts // form enabled $view = view('posts.delete')->with(['posts' => $this->getUserPosts(), 'posts_sort_by_names' => Post::getSortFunctionNames(true), 'posts_enable_form' => true]); return $view; }