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; }