From 5a8c47e29afdbb61c32c1e03162abb1bb871ee9e Mon Sep 17 00:00:00 2001 From: horus Date: Thu, 2 Apr 2020 21:52:04 +0200 Subject: Initial commit. --- app/Http/Controllers/IndexController.php | 102 +++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 app/Http/Controllers/IndexController.php (limited to 'app/Http/Controllers/IndexController.php') diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php new file mode 100644 index 0000000..7ae362a --- /dev/null +++ b/app/Http/Controllers/IndexController.php @@ -0,0 +1,102 @@ +orWhere('name', $topic); + $articles = $articles->get()->first(); + if ( is_null($articles) ) { + abort(404); + } + $articles = $articles->getArticles(); + $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('url', 'like', $q) + ->orWhere('excerpt_html', 'like', $q); + }); + } + $count = $articles->count(); + $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'); + + return view('topicindex', ['topics' => $categories]); + } + + public function random() { + $articles = new Article; + $articles = $articles->inRandomOrder(); + $count = $articles->count(); + $articles = $articles->simplePaginate(10); + + return view('list', ["articles" => $articles, "count" => $count]); + } +} -- cgit v1.2.3