public function showPost($slug, Request $request) { $post = Post::with('tags')->whereSlug($slug)->firstOrFail(); $tag = $request->get('tag'); if ($tag) { $tag = Tag::whereTag($tag)->firstOrFail(); } return view('construct::' . $post->layout, compact('post', 'tag')); }
/** * Return the field values from the model * * @param integer $id * @param array $fields * @return array */ protected function fieldsFromModel($id, array $fields) { $post = Post::findOrFail($id); $fieldNames = array_keys(array_except($fields, ['tags'])); $fields = ['id' => $id]; foreach ($fieldNames as $field) { $fields[$field] = $post->{$field}; } $fields['tags'] = $post->tags()->lists('tag')->all(); return $fields; }
/** * Return data for a tag index page * * @param string $tag * @return array */ protected function tagIndexData($tag) { $tag = Tag::where('tag', $tag)->firstOrFail(); $reverse_direction = (bool) $tag->reverse_direction; $posts = Post::where('published_at', '<=', Carbon::now())->whereHas('tags', function ($q) use($tag) { $q->where('tag', '=', $tag->tag); })->where('is_draft', 0)->orderBy('published_at', $reverse_direction ? 'asc' : 'desc')->simplePaginate(config('site.posts_per_page')); $posts->addQuery('tag', $tag->tag); $page_image = $tag->page_image ?: config('site.page_image'); return ['title' => $tag->title, 'subtitle' => $tag->subtitle, 'posts' => $posts, 'page_image' => $page_image, 'tag' => $tag, 'reverse_direction' => $reverse_direction, 'meta_description' => $tag->meta_description ?: \config('site.description')]; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $post = Post::findOrFail($id); $post->tags()->detach(); $post->delete(); return redirect()->route('admin.post.index')->withSuccess('Post deleted.'); }