/** * Display a listing of the category. * * @param Request $request * @return \Illuminate\Http\Response */ public function index(Request $request) { $filter = $request->get('filter', 'merge'); $sub = explode(':', $filter); if ($sub[0] == 'subcategory') { if (isset($sub[1]) && $sub[1] > 0) { $menu = Subcategory::whereCategoryId($sub[1])->get(); } else { $menu = Subcategory::all(); } } else { if ($filter == 'category') { $menu = Category::all(); } else { $menu = Category::with('subcategories')->get(); } } return ['request_id' => uniqid(), 'status' => 'success', 'timestamp' => Carbon::now(), 'categories' => $menu]; }
/** * Show the form for editing the specified article. * * @param $slug * @return \Illuminate\Http\Response */ public function edit($slug) { /* * -------------------------------------------------------------------------- * Show edit form * -------------------------------------------------------------------------- * Populate category into list for build drop down, and try catch old * subcategory input because it depends on category, by default subcategory * should be exist on edit because all article should have it. */ $article = Article::whereSlug($slug)->firstOrFail(); $categories = Category::pluck('category', 'id'); $subcategories = null; if (Input::old('category', '') != '') { $subcategories = Category::findOrFail(Input::old('category'))->subcategories; } else { $subcategories = Subcategory::whereCategoryId($article->subcategory->category->id)->get(); } return view('contributor.article_edit', compact('article', 'categories', 'subcategories')); }