/** * 記事一覧 */ public function getIndex() { $allCategories = array("すべて"); $categories = Category::where('user_id', Auth::user()->id)->lists('name', 'id'); $allCategories += $categories; // 値の取得 $title = Input::get('title'); $category = Input::get('category_id'); $content = Input::get('content'); // 最新投稿順_ $query = Post::latest('id'); // もしタイトルがあれば if (!empty($query)) { $query->where('title', 'like', '%' . $title . '%'); } // もしカテゴリーがすべて(0)でなかったら if ($category != 0) { $query->where('category_id', $category); } // もし内容があれば if (!empty($content)) { $query->where('content', 'like', '%' . $content . '%'); } // 認証されたユーザの記事のみで1ページあたりの件数 $posts = $query->where('user_id', Auth::user()->id)->paginate(7); return view('posts.index', compact('allCategories', 'categories', 'title', 'category', 'content', 'posts')); }