public function edit($id) { $post = Post::find($id); $cat = Category::all(); $catname = Category::where('id', $post->category)->first()->category; return view('edit')->with('post', $post)->with('cat', $cat)->with('catname', $catname); }
public function catposts($category) { if (is_numeric($category)) { $cat = Category::find($category)->id; } else { $column = 'category'; // This is the name of the column you wish to search $cat = Category::where($column, '=', $category)->first()->id; } $catname = Category::find($cat); $posts = Post::where('category', $cat)->orderBy('id', 'desc')->paginate(5); //var_dump($posts); return view('catposts')->with('posts', $posts)->with('catname', $catname); }