コード例 #1
0
 /**
  * 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.');
 }
コード例 #2
0
 /**
  * @param $slug
  * @return mixed
  */
 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($post->layout, compact('post', 'tag', 'slug'));
 }
コード例 #3
0
 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;
 }
コード例 #4
0
ファイル: BlogIndexData.php プロジェクト: ReyRodriguez/kuento
 /**
  * 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('blog.posts_per_page'));
     $posts->addQuery('tag', $tag->tag);
     $page_image = $tag->page_image ?: config('blog.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('blog.description')];
 }
コード例 #5
0
ファイル: RssFeed.php プロジェクト: ReyRodriguez/kuento
 /**
  * Return a string with the feed data
  *
  * @return string
  */
 protected function buildRssData()
 {
     $now = Carbon::now();
     $feed = new Feed();
     $channel = new Channel();
     $channel->title(config('blog.title'))->description(config('blog.description'))->url(url())->language('en')->copyright('Copyright (c) ' . config('blog.author'))->lastBuildDate($now->timestamp)->appendTo($feed);
     $posts = Post::where('published_at', '<=', $now)->where('is_draft', 0)->orderBy('published_at', 'desc')->take(config('blog.rss_size'))->get();
     foreach ($posts as $post) {
         //dd($post);
         $item = new Item();
         $item->title($post->title)->description($post->subtitle)->url($post->url())->pubDate(strtotime($post->published_at))->guid($post->url(), true)->appendTo($channel);
     }
     $feed = (string) $feed;
     // Replace a couple items to make the feed more compliant
     $feed = str_replace('<rss version="2.0">', '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">', $feed);
     $feed = str_replace('<channel>', '<channel>' . "\n" . '
         <atom:link href="' . url('/rss') . '" rel="self" type="application/rss+xml" />', $feed);
     return $feed;
 }