From 52c8f60a95f661e2077e1cf8f05dcd760924443a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 7 Feb 2019 11:58:47 -0700 Subject: [PATCH] Add AdminDiscoverController --- .../Admin/AdminDiscoverController.php | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 app/Http/Controllers/Admin/AdminDiscoverController.php diff --git a/app/Http/Controllers/Admin/AdminDiscoverController.php b/app/Http/Controllers/Admin/AdminDiscoverController.php new file mode 100644 index 00000000..f19d01bc --- /dev/null +++ b/app/Http/Controllers/Admin/AdminDiscoverController.php @@ -0,0 +1,105 @@ +paginate(10); + return view('admin.discover.home', compact('categories')); + } + + public function discoverCreateCategory() + { + return view('admin.discover.create-category'); + } + + public function discoverCreateCategoryStore(Request $request) + { + $this->validate($request, [ + 'name' => 'required|string|min:1', + 'active' => 'required|boolean', + 'media' => 'nullable|integer|min:1' + ]); + + $name = $request->input('name'); + $slug = str_slug($name); + $active = $request->input('active'); + $media = (int) $request->input('media'); + + $media = Media::findOrFail($media); + + $category = DiscoverCategory::firstOrNew(['slug' => $slug]); + $category->name = $name; + $category->active = $active; + $category->media_id = $media->id; + $category->save(); + return $category; + } + + public function discoverCategoryEdit(Request $request, $id) + { + $category = DiscoverCategory::findOrFail($id); + return view('admin.discover.show', compact('category')); + } + + public function discoverCategoryUpdate(Request $request, $id) + { + $this->validate($request, [ + 'name' => 'required|string|min:1', + 'active' => 'required|boolean', + 'media' => 'nullable|integer|min:1', + 'hashtags' => 'nullable|string' + ]); + $name = $request->input('name'); + $slug = str_slug($name); + $active = $request->input('active'); + $media = (int) $request->input('media'); + $media = Media::findOrFail($media); + + $category = DiscoverCategory::findOrFail($id); + $category->name = $name; + $category->active = $active; + $category->media_id = $media->id; + $category->save(); + + return $category; + } + + public function discoveryCategoryTagStore(Request $request) + { + $this->validate($request, [ + 'category_id' => 'required|integer|min:1', + 'hashtag' => 'required|string', + 'action' => 'required|string|min:1|max:6' + ]); + $category_id = $request->input('category_id'); + $category = DiscoverCategory::findOrFail($category_id); + $hashtag = Hashtag::whereName($request->input('hashtag'))->firstOrFail(); + + $tag = DiscoverCategoryHashtag::firstOrCreate([ + 'hashtag_id' => $hashtag->id, + 'discover_category_id' => $category->id + ]); + + if($request->input('action') == 'delete') { + $tag->delete(); + return []; + } + return $tag; + } +} \ No newline at end of file