public function getData() { $posts = Post::minimum()->get(); $json = '{"records" : ' . json_encode(Post::minimum()->with('categories')->with('users')->take(2)->get()) . '}'; /*this how to make json formated for table relation*/ return $json; }
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()); }
public function postDestroy() { $post = Post::find(Input::get('id')); if ($post) { $post->delete(); return Redirect::back()->with('message', 'Post Deleted'); } return Redirect::back()->with('message', 'Something went wrong, please try again'); }