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>