orWhere('name', $topic); $articles = $articles->get()->first(); if ( is_null($articles) ) { abort(404); } $articles = $articles->getArticles(); $articles = $articles->orderBy('impact', 'desc'); $count = $articles->count(); $articles = $articles->simplePaginate(10); return view('list', ["articles" => $articles, "count" => $count]); } public function new() { $articles = Article::orderBy('created_at', 'desc'); $count = $articles->count(); $articles = $articles->simplePaginate(10); return view('list', ["articles" => $articles, "count" => $count]); } public function search(Request $request) { $search_unsafe = $request->input("q"); if ( "" == $search_unsafe ) { $search_unsafe = ""; } $search_unsafe = explode(",", $request->input("q")); $articles = new Article; if ( "on" == $request->input("onlypopular") ) { $articles = $articles->setTable('view_popular'); } foreach($search_unsafe as $q) { $q = Helper::escapeLike($q); $q = "%".$q."%"; $articles = $articles->where(function ($query) use ($q) { $query->whereHas('getCategories', function ($query) use ($q){ $query->where('name', 'like', $q); }) ->orWhere('title', 'like', $q) ->orWhere('excerpt_html', 'like', $q); }); } $count = $articles->count(); if ( "on" == $request->input("onlypopular") ) { $articles = $articles->orderBy('impact', 'desc'); } $articles = $articles->orderBy('created_at', 'desc'); $articles = $articles->simplePaginate(10); return view('list', ["articles" => $articles, "count" => $count]); } public function popular() { $articles = new Article; $articles = $articles->setTable('view_popular'); $count = $articles->count(); $articles = $articles->simplePaginate(10); return view('list', ["articles" => $articles, "count" => $count]); } function topicindex() { $categories = Category::orderBy('name'); $letters = DB::select("SELECT DISTINCT LEFT(name, 1) as name FROM category ORDER BY left(name, 1);"); return view('topicindex', ['topics' => $categories, 'letters' => $letters]); } public function random() { $articles = new Article; $articles = $articles->inRandomOrder(); $count = $articles->count(); $articles = $articles->simplePaginate(10); return view('list', ["articles" => $articles, "count" => $count]); } public function populartopics() { $topics = DB::select(" SELECT c.name, count(c.name) AS count FROM category AS c JOIN article_category AS ac ON c.id = ac.category_id GROUP BY c.name ORDER BY count(c.name) DESC;"); #echo "
"; var_dump($topics);exit;
return view('topicpopular', ['topics' => $topics ]);
}
}