douxie5176 2018-07-10 08:57
浏览 75

Laravel 5.5,使用3个下拉按钮过滤器,无需重置第一个和第二个过滤器

I have 3 Dropdown menu to filter applicants data in my list, from the database but when I filter with the 2nd filter, the 1st filter will reset it.. I want to do the filter records the 1st filter and then move to 2nd filter without resetting it. and then apply filters to get the data

this is my first time using laravel and everything inside it. If anyone has a way how this is work, I'm really thank you for that I'm really appreciate that.

this is the screenshot of the button the applicants list

this is the controller

public function index()
{
    $branches = \App\Branch::all();
    $batches = \App\Batch::all();
    $users = \App\User::all();
    $user_details = \App\UserDetail::all();

    $applicant_info = DB::table('applicants')
    ->join('user_details', 'applicants.fk_user_details_id', '=', 'user_details.user_detail_id')
    ->join('users', 'users.id', '=', 'user_details.fk_users_id')
    ->join('batches', 'applicants.fk_batches_id', '=', 'batches.batches_id')
    ->join('branches', 'applicants.fk_branches_id', '=', 'branches.branches_id')
    ->select('applicants.*', 'user_details.*', 'branches.*', 'batches.*', 'users.*')
    ->orderBy('applicants_id', 'asc');

    if(request()->has('country')){
        $applicant_info = $applicant_info->where('applicants.applicant_country', request('country'));
    }

    if(request()->has('branch')){
        $applicant_info = $applicant_info->where('branches.branch_name', request('branch'));
    }

    if(request()->has('batch')){
        $applicant_info = $applicant_info->where('batches.batch_name', request('batch'));
    }


    $applicant_info = $applicant_info->get();

    // $applicants = $applicants->paginate(5)->appends(['country' => request('country')]);

    $branch = \App\Branch::orderBy('branch_name')->pluck('branch_name')->unique();

    $batch = \App\Batch::orderBy('batch_name')->pluck('batch_name')->unique();

    $countries = \App\Applicant::orderBy('applicant_country')->pluck('applicant_country')->unique();


    return view('backend.applicant_management.applicant_list', ['applicant_info'=>$applicant_info, 'branches'=>$branches, 'batches'=>$batches, 'users'=>$users, 'countries'=>$countries, 'branch'=>$branch, 'batch'=>$batch]);

}

and this is the view.blade

<div class="pull-right">
   <div class="btn-group">
      <button data-toggle="dropdown" class="btn btn-default dropdown-toggle" type="button" aria-expanded="false">Branch Name<span class="caret"></span>
      </button>
      <ul role="menu" class="dropdown-menu" name="branch">
         <li><a href="/applicant_list">All Branch</a>
            @foreach($branch as $branch)
         <li><a id="filterbranch" href="/applicant_list/?branch={{ $branch }}"> {{ $branch }}</a></li>
         @endforeach
      </ul>
   </div>
   <div class="btn-group">
      <button data-toggle="dropdown" class="btn btn-default dropdown-toggle" type="button" aria-expanded="false">Batch Number<span class="caret"></span>
      </button>
      <ul role="menu" class="dropdown-menu" name="batch">
         <li><a href="/applicant_list">All Batch</a>
            @foreach($batch as $batch)
         <li><a href="/applicant_list/?batch={{ $batch }}"> {{ $batch }}</a></li>
         @endforeach
      </ul>
   </div>
   <div class="btn-group">
      <button data-toggle="dropdown" class="btn btn-default dropdown-toggle" type="button" aria-expanded="false">Country<span class="caret"></span>
      </button>
      <ul role="menu" class="dropdown-menu" name="country">
         <li><a href="/applicant_list">All Country</a></li>
         @foreach($countries as $country)
         <li><a href="/applicant_list/?country={{ $country }}"> {{ $country }}</a></li>
         @endforeach
      </ul>
   </div>
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 touchsocket udp组播
    • ¥20 MAC怎么安装Silverlight 插件?以及安装了怎么启用
    • ¥15 VS2012中查询语句无法填入解析,数值传不进去
    • ¥15 gis系统开发出现命名空间“ESRI.ArcGIS”中不存在类型或命名空间名“Analyst3D”报错
    • ¥15 怎么让ai定时给我发信息 c#或者python
    • ¥15 scrapy的Error
    • ¥15 RBF-VSG姚凤军论文复现问题
    • ¥30 开发一个APP商城在制作tabbar的时候运行不了代码没有检查出错误,但是显示不出tabbar,以下为运行结果,如何解决?
    • ¥15 多网卡服务器中winform如何绑定指定网卡
    • ¥15 关于#python#pandas#的问题,想要实现:多个TXT导入Excel,进行分列,不同txt之间都从第一行开始,请各位专家解答!