TP5 paginate()分頁後給結果集追加字段和數據

public function index(){
    $sql = "";
    $list = "";
    $pagenumber = 20;//默認分頁條數
    
    //查詢數據
    $list = Db::name('wcmall_type','id,name,sort')->where($sql)->order('sort asc')->paginate($pagenumber,false,['query'=>request()->param()])->each(function($item, $key){
        $wctypeid = $item["id"]; //獲取數據集中的id
        $num = Db::name('wcmall_type_attribute')->where("wctypeid='$wctypeid'")->count('id'); //根據ID查詢相關其餘信息
        $item['num'] = $num; //給數據集追加字段num並賦值
        return $item;
    });
    $page = $list->render();
    
    
    return view('type/index',['list'=>$list,'page'=>$page,'title'=>'商品類型']);
}
相關文章
相關標籤/搜索