lareavel 日期搜索条件的记录

1.无条件不加东西 2.必须两个区间 3.优化再优化,切勿急于完成导致代码冗余

if($request->input('time1') && $request->input('time2')){
            $time1 = strtotime($request->input('time1').' 00:00:00');
            $time2 = strtotime($request->input('time2').' 23:59:59');

            if($request->input('type') == 1){
                //日期类型为 出发日期
                $books->whereBetween('_boarding_date',[$time1 , $time2]);
            } else {
                //日期类型为 下单、报名日期
                $books->whereBetween('joinDate',[$time1 , $time2]);
            }
        }

        $books = $books->orderBy('.fin_income_status.b_id','desc')
            ->paginate(50);
<div class="row">
    <div class="col-sm-5">
        <div class="dataTables_info" role="status" aria-live="polite">
            当页 {{ $books->count() }} 条数据,
            共 {{ $books->total() }} 条
        </div>
    </div>
    <div class="col-sm-7">
        <div class="dataTables_paginate">
            {{ $books->appends([
                'uid' => $request->uid,
                'time1' => $request->time1,
                'time2' => $request->time2,
                'type' => $request->type,
            ])->links() }}
        </div>
    </div>
</div>
最后修改:2019-02-17 08:51:51
0