public static function list_paginate($term_id = 0, $term_type = 'category', $per_page = 2) { if ($term_id) { $terms = Term::get_item_by_type($term_type, $term_id); $category_ids = array_column($terms, 'id'); $category_ids[] = $term_id; $posts = Post::leftJoin('relations', 'posts.id', '=', 'relations.object_id')->whereIn('relations.term_id', $category_ids)->orderBy('id', 'desc')->paginate($per_page); } else { $posts = Post::orderBy('id', 'desc')->paginate($per_page); } return $posts; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { if ($request->has('search')) { $posts = Post::where('id', 'LIKE', "%" . $request->input('search') . "%")->orWhere('title', 'LIKE', "%" . $request->input('search') . "%")->paginate(5); } else { if ($request->has('sortby')) { $posts = Post::orderBy($request->input('sortby'))->paginate(5); } else { $posts = Post::paginate(5); } } $posts->setPath(url() . '/back/post'); return view('pages.admin.post.list', ['posts' => $posts]); }
public function index() { $posts = \App\Model\Post::orderBy('id', 'desc')->paginate(25); return view('post/list')->with('posts', $posts)->with('type', ['name' => 'post', 'title' => '帖子']); }