/** * Include media. * * @param \Flashtag\Posts\Category $category * @return \League\Fractal\Resource\Item */ public function includeMedia(Category $category) { if (!$category->hasMedia()) { return null; } return $this->item($category->media, new MediaTransformer()); }
/** * Display the specified resource. * * @param string $category_slug * @return \Illuminate\Http\Response */ public function show($category_slug) { $category = Category::getBySlug($category_slug); $posts = Post::whereHas('category', function ($query) use($category_slug) { $query->where('slug', $category_slug); })->simplePaginate(); return view('flashtag::categories.show', compact('category', 'posts')); }
public function home() { $mostViewed = Post::mostViewed(5)->get(); $leastViewed = Post::leastViewed(5)->get(); $postCount = Post::count(); $categoryCount = Category::count(); $tagCount = Tag::count(); $pageCount = Page::count(); return view('admin::home', compact('mostViewed', 'leastViewed', 'mostViews', 'leastViews', 'postCount', 'categoryCount', 'tagCount', 'pageCount')); }
public function edit($id) { $post = Post::with('author', 'fields', 'category', 'tags')->findOrFail($id); $post->lock(auth()->user()->id); $categories = Category::all(['id', 'name']); $tags = Tag::all(['id', 'name']); $authors = Author::all(['id', 'name']); $fields = Field::all(); return view('admin::posts.edit', compact('post', 'categories', 'tags', 'authors', 'fields')); }
/** * @param int $id * @return \Dingo\Api\Http\Response */ public function destroy($id) { $category = $this->category->findOrFail($id); $category->delete(); return $this->response->item($category, new CategoryTransformer()); }
/** * @param int $id */ public function destroy($id) { $field = Category::findOrFail($id); $field->delete(); }
/** * @param Category $category * @param \Illuminate\Http\Request $request */ private function syncTagsFromRequest(Category $category, $request) { $tags = $request->get('tags', []); $category->tags()->sync($tags); }
/** * Display the default page. * * @return \Illuminate\Http\Response */ public function index() { $posts = Post::getLatest(10); $categories = Category::all(); return view('flashtag::home', compact('posts', 'categories')); }