/** * 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')); }