Пример #1
0
 public function getCategory($id)
 {
     $category = Category::find($id);
     $posts = $category->posts()->where('enabled', '=', '1')->where('post_date', '<=', Carbon::now())->orderBy('post_date', 'desc')->paginate(4);
     //here some example using manual DB select and make paginator with that
     //$posts = DB::select("SELECT p.id, p.title, p.article, p.created_at, p.head_article, c.name FROM sb_posts as p, sb_post_to_cat as pc, sb_categories as c  WHERE c.id = '3' AND c.id = pc.category_id AND pc.post_id = p.id");
     //$posts = new LengthAwarePaginator(array_slice($posts, 1, 4), $category->posts->count(), 4);
     return View::make('blog.pages.category')->with('posts', $posts)->with('category', $category)->with('lastposts', Post::enabled()->minimum()->take(4)->get())->with('lastcomments', Comment::enabled()->take(4)->orderBy('created_at', 'DESC')->get())->with('categories', Category::all());
 }
Пример #2
0
 public function getEdit($id)
 {
     $post = Post::find($id);
     $categories = array();
     $postcats = array();
     foreach (Category::all() as $category) {
         $categories[$category->id] = $category->name;
     }
     if ($post) {
         foreach ($post->categories as $postcat) {
             $postcats[$postcat->id] = $postcat->id;
         }
         return View::make('blog.posts.edit')->with('post', $post)->with('categories', $categories)->with('postcats', $postcats);
     }
 }
 public function getIndex()
 {
     return View::make('blog.categories.index')->with('categories', Category::all());
 }