/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validator = Validator::make(Input::all(), Post::$rules); if ($validator->fails()) { Session::flash('errorMessage', 'Something went wrong here!'); return Redirect::back()->withErrors($validator)->withInput(); } else { $post = new Post(); $post->title = Input::get('title'); $post->body = Input::get('body'); $post->user_id = Auth::id(); if (Input::hasFile('picture')) { if (Input::file('picture')->isValid()) { Storage::upload(Input::file('picture'), "{$post->picture}" . "jpg"); } $post->picture = Input::file('picture'); } if (Input::has('tags')) { $post->tags = implode(', ', Input::get('tags')); } $post->save(); $posts = Post::paginate(5); Session::flash('goodMessage', 'All went right here!'); return View::make('posts/index')->with('posts', $posts); } }
/** * Display a listing of the resource. * * @return Index View */ public function index() { $posts = Post::paginate(5); // if(!$post->count() === 0){ // Session::flash('errorMessage', 'There were no results matching your search.'); // } return View::make('posts.index')->with('posts', $posts); }
public function index() { $data["_title"] = array("top" => "最新消息", "main" => "Home", "sub" => "post"); $data["active"] = "news"; $cate_array = array(); $cates = Cate::where("type", "!=", "工程進度")->get(); foreach ($cates as $cate) { $cate_array[$cate->id] = $cate->name; } $data["cates"] = $cate_array; $data["result"] = Post::paginate(10); return View::make('admin.posts.index', $data); }
/** * Get all posts * @param int $perPage $posts * @return JSON */ public function getPosts($perPage) { // get posts $posts = Post::paginate($perPage); // paginatation array $postsResponse['total'] = $posts->getTotal(); $postsResponse['per_page'] = $posts->getPerPage(); $postsResponse['current_page'] = $posts->getCurrentPage(); $postsResponse['last_page'] = $posts->getLastPage(); $postsResponse['from'] = $posts->getFrom(); $postsResponse['to'] = $posts->getTo(); // self link $postsResponse['links'] = ['self' => action('PostController@index')]; // data param foreach ($posts as $post) { $postsResponse['data'][] = ['type' => 'posts', 'id' => $post->id, 'attributes' => $post]; } // Create Response header $response = Response::make($postsResponse, 200); $response->header('Content-Type', 'application/vnd.api+json'); return $response; }
/** * Display a listing of the resource. * * @return Response */ public function index() { $posts = Post::paginate(6); return View::make('posts.index')->with(array('posts' => $posts)); }
public function paginate($limit = null) { return Post::paginate($limit); }
/** * Display a listing of the resource. * GET /post * * @return Response */ public function index() { $posts = Post::paginate(3); return View::make('admin.posts.post-list', compact('posts')); }
public function showIndex() { $posts = Post::paginate(4); return View::make('posts.index')->with(['posts' => $posts]); }
/** * Display a listing of the resource. * * @return Response */ public function index() { #get all posts $posts = Post::paginate(10); return View::make('blog')->with('posts', $posts); }
public function index() { $r_slide = Slideshow::all(); $r_post = Post::paginate(3); return View::make('pages.home', compact('r_post', 'r_slide')); }