public function index() { // キーワード受け取り $keyword = \Input::get('keyword'); // クエリ生成 $query = Post::query(); // if (!empty($keyword)) // { // $query->where('title','like','%'.$keyword.'%')->orWhere('name','like','%'.$keyword.'%'); // } $posts = $query->where('parent_id', null)->orderBy('created_at', 'desc')->paginate(5); return view('post.index', compact('posts', 'keyword')); }
public function index(Request $request) { $posts = Post::query()->select("*")->orderBy("created_at", "dsc")->paginate(10); return view("index", ["posts" => $posts]); }