sort = $achievement->id; $achievement->save(); } public static function getPaginateList($categoryId, $per = 20, $isSample = false , $onlyVisible = false, $order = []) { $paginate = [ 'list_rows' => $per ]; if(empty($order)) { $order = ['sort'=>'desc']; } return self::where('category_id', $categoryId) ->when($onlyVisible, function ($query) { $query->where('visible', 1); }) ->order($order) ->paginate($paginate, $isSample); } public static function getListByCategoryId($categoryId, $per = 20, $onlyVisible = false, $order = []) { if(empty($order)) { $order = ['sort'=>'desc']; } $items = self::where('category_id', $categoryId) ->when($onlyVisible, function ($query) { $query->where('visible', 1); }) ->order($order) ->limit($per) ->column('*', 'id'); if(count($items) > 0) { $ids = array_keys($items); $infoList = AchievementInfo::getGroupByAchievementIds($ids, $onlyVisible); foreach ($items as &$item) { $item['infos'] = $infoList[$item['id']] ?? []; } unset($item); } return array_values($items); } }