예제 #1
0
 function getPosts()
 {
     $c = Input::get('c');
     $s = Input::get('s');
     if ($c == 0 && $s === '') {
         $posts = Post::with('category')->with('user')->with('tags')->with('approves')->orderBy('id', 'desc')->paginate(15);
     } else {
         if ($s !== '' && $c == 0) {
             $posts = Post::with('category')->with('user')->with('tags')->with('approves')->where('title', 'LIKE', '%' . $s . '%')->orderBy('id', 'desc')->paginate(15);
         } else {
             $posts = Post::with('category')->with('user')->with('tags')->with('approves')->where('category_id', $c)->where('title', 'LIKE', '%' . $s . '%')->orderBy('id', 'desc')->paginate(15);
         }
     }
     return response()->json($posts);
 }
예제 #2
0
 public function getAll()
 {
     $books = Post::with('category')->where('category_id', '=', '2')->get();
     return response()->json($book);
 }