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

时间:2018-07-10 08:57:27

标签: javascript php css laravel

我有3个下拉菜单,用于从数据库中过滤列表中的申请人数据 但是当我使用第二个过滤器进行过滤时,第一个过滤器会将其重置。 我想做过滤器记录第一个过滤器,然后移动到第二个过滤器而不重置它。然后应用过滤器以获取数据

这是我第一次使用laravel及其内部的所有内容。 如果有人有办法解决这个问题,我真的非常感谢您 我真的很感激。

这是按钮的屏幕截图 the applicants list

这是控制器

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]);

}

这是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 个答案:

没有答案