Laravel-将文本框过滤器转换为下拉过滤器

时间:2019-07-04 17:02:51

标签: laravel

我设计了一个报表应用程序,该应用程序使用日期和文本框进行过滤:

public function revenueOverall(Request $request)
{

    $data['title'] = 'Revenue Overall';

    $revenuedetails = DB::table('vw_revenue_report_dashboard as g')
    ->select(
       DB::raw('DATE(g.created_at) as created_date'),
       'g.msisdn', 
       'g.channel', 
       'g.amount'              
  )
 ->orderByRaw('g.created_at DESC'); 


    $start_date = $request->start_date;
    $end_date = $request->end_date; 

    $render=[];  
    if(isset($request->start_date) && isset($request->end_date))
    {
        $revenuedetails=$revenuedetails->whereBetween('created_at',[$start_date.' 00:00:00',$end_date.' 23:59:59']);
        $render['start_date']=$request->start_date;
        $render['end_date']=$request->end_date;
    }elseif(isset($request->start_date))
    {
        $revenuedetails=$revenuedetails->where('created_at',$request->start_date);
        $render['start_date']=$request->start_date;
    }        
    if(isset($request->msisdn))
    {
        $revenuedetails=$revenuedetails->where('msisdn','like','%'.$request->msisdn.'%');
        $render['msisdn']=$request->msisdn;
    } 
    if(isset($request->channel))
    {
        $revenuedetails=$revenuedetails->where('channel','like','%'.$request->channel.'%');
        $render['channel']=$request->channel;
    }        
    $revenuedetails= $revenuedetails->orderBy('created_at','DESC');
    $revenuedetails= $revenuedetails->paginate(15);
    $revenuedetails= $revenuedetails->appends($render);
    $data['revenuedetails'] = $revenuedetails;

return view('report.revenueOverall',$data);        
}

查看:

filter_image

    <div class="row" style="margin-bottom: 10px">
    {{ Form::model(request(),['method'=>'get']) }}
    <div class="col-sm-2">
         {{ Form::text('msisdn',null,['class'=>'form-control','placeholder'=>'MSISDN']) }}
    </div>
    <div class="col-sm-2">
         {{ Form::text('channel',null,['class'=>'form-control','placeholder'=>'Channel']) }}
    </div>        
    <div class="col-sm-3">
        {{ Form::date('start_date',null,['class'=>'form-control','placeholder'=>'Date']) }}
    </div>
    <div class="col-sm-3">
        {{ Form::date('end_date',null,['class'=>'form-control','placeholder'=>'Date']) }}
    </div>           
    <div class="col-xs-2">
        {{ Form::submit('Search',['class'=>'btn btn-warning']) }}
        <a href="{{ route('revenueoverallexport') }}" class="btn btn-primary"><i class="fa fa-file-excel-o"></i> Excel</a>
    </div>
    {{ Form::close() }}
</div>

从上面的过滤器中,我可以按日期,文本框(通道和MSISSDN)进行过滤。一切工作正常。但是我想将过滤器的通道改为下拉过滤器,而不是文本框过滤器。

我将以下代码用于通道文本框过滤器,但希望转换为下拉菜单。

        if(isset($request->channel))
    {
        $revenuedetails=$revenuedetails->where('channel','like','%'.$request->channel.'%');
        $render['channel']=$request->channel;
    }  

这是刀片:

 {{ Form::text('channel',null,['class'=>'form-control','placeholder'=>'Channel']) }}

表中的字段为:

    tid, created_at,msisdn, channel, amount

如何修改原始代码以实现此目的? 请注意,所有内容均来自同一张表。它应该选择与众不同。

0 个答案:

没有答案