使用paginate分页后数据处理
1 public function index(){ 2 $sql = ""; 3 $list = ""; 4 $pagenumber = 20;//默认分页条数 5 6 //查询数据 7 $list = Db::name('wcmall_type','id,name,sort')->where($sql)->order('sort asc')->paginate($pagenumber,false,['query'=>request()->param()])->each(function($item, $key){ 8 $wctypeid = $item["id"]; //获取数据集中的id 9 $num = Db::name('wcmall_type_attribute')->where("wctypeid='$wctypeid'")->count('id'); //根据ID查询相关其他信息 10 $item['num'] = $num; //给数据集追加字段num并赋值 11 return $item; 12 }); 13 $page = $list->render(); 14 15 16 return view('type/index',['list'=>$list,'page'=>$page,'title'=>'商品类型']); 17 }
人生得意须尽欢,莫使金樽空对月.