• laravel一个页面两个表格分页处理


    关键是看懂laravel自带的 paginate() 方法。

    在Builder.php文件(项目名称/laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php)里面有一个分页的方法paginate()。

    页面:

    <div id="a"  @if(isset($attr) && $attr[1]  == 'spage') style="display: none" @else style="display: block" @endif  >
        @if(empty($goods))
            <div class="cell">
                <div>
                    <p>暂无商品</p>
                </div>
            </div>
        @else
            <table>
            @foreach($goods as $v)
                <div class="cell">
                    <img src="{{$v->picture}}" alt="暂无图片" />
                    <div>
                        <p>{{$v->name}}</p>
                        <p>所需积分:{{$v->exchange_integral}}</p>
                        <p>库存数量:{{$v->goods_number}}</p>
                        <div>立即兑换</div>
                    </div>
                </div>
                <div class="zhan"></div>
            @endforeach
            </table>
        @endif
        <div class="cell" style="text-align: center" >{{$goods->appends(['spage'=>$dui->currentPage()])->links()}}<br/></div>
    </div>
    <div id="b" @if(isset($attr) && $attr[1]  == 'spage') style="display: block" @else style="display: none" @endif >
        @if(empty($dui))
            <div class="cell">
                <div>
                    <p>暂无可兑换商品</p>
                </div>
            </div>
        @else
            <table>
                @foreach($dui as $v)
                    <div class="cell">
                        <img src="{{$v->picture}}" alt="暂无图片" />
                        <div>
                            <p>{{$v->name}}</p>
                            <p>所需积分:{{$v->exchange_integral}}</p>
                            <p>库存数量:{{$v->goods_number}}</p>
                            <div>立即兑换</div>
                        </div>
                    </div>
                    <div class="zhan"></div>
                @endforeach
            </table>
        @endif
        <div class="cell" style="text-align: center" >{{$dui->appends(['fpage'=>$goods->currentPage()])->links()}} <br/></div>
    </div>

    后台:

    //商品列表
        public function goodsList(Request $request)
        {
            //所有的商品
            $goods = Goods::orderBy('updated_at','desc')->paginate(2,['*'],'fpage');
            //所有的可以兑换的商品
            $userid = $this->getWxUserId();
            $user = User::where('wx_userid',$userid)->first();
            $point= $user->point;           //用户积分
            $dui   = Goods::where('exchange_integral','<=',$point)->orderBy('updated_at','desc')->paginate(1,['*'],'spage');
    
            //根据键值判断当前页面
            $attr = array() ;
            foreach($_GET as $k=>$v){
                $attr[] = $k;
            }
            //首次进入,初始化
            if(empty($attr)){
                $attr[0] = 'spage';
                $attr[1] = 'fpage';
            }
            return view("marketing.goods.goodsList",compact('goods','dui','attr'));
        }

    引用出处:

    https://www.cnblogs.com/smallyi/p/6627855.html

  • 相关阅读:
    fastjson生成和解析json数据
    fastJson API
    js实现class样式的修改、添加及删除的方法
    jquery ajax局部加载方法介绍
    jquery 动态添加和删除 ul li列表
    spring mvc3中的addFlashAttribute方法
    Spring MVC 3 : 一次上传多个文件
    pring mvc 批量上传+文件上传
    SpringMVC批量上传
    Android ADT Bundle(Eclipse with ADT) ADT R23
  • 原文地址:https://www.cnblogs.com/wanlibingfeng/p/8648979.html
Copyright © 2020-2023  润新知