public function showCategory($slug) { $categories = Category::all(); $category = Category::whereSlug($slug)->first(); $posts = Post::isPublished()->where('category_id', $category->id)->paginate(10); return view('blog::category.show')->withPageTitle($category->name)->withPosts($posts)->withCategory($category)->withCategories($categories)->withActiveCategory($category->id); }
public function ajax_category_create() { $category_name = Input::get('category_name'); if (strlen($category_name) == 0) { return response()->json(['status' => 'error', 'error' => 'Categories cannot have empty names.']); } $category = Category::whereName($category_name)->first(); if ($category) { return response()->json(['status' => 'error', 'error' => 'This category already exists.']); } $category = Category::create(['name' => $category_name, 'slug' => Str::slug($category_name)]); return response()->json(['status' => 'success', 'object' => $category]); }