Jan 19, 2017
0
Level 13
How to filter data individually and combined?
I have filter function in my app and i want like if i submit the form with input "course" then it show result according to course_id = request->course, if he submit the form with year input then it show result according to "year_of_addmission = request->year", if he submit the form both input "year" and "course" then result show according to "course_id=request->course" and "year_of_addmission=request->year"
my controller
$search = $request->search;
$course = $request->course;
$year = $request->year;
if($search)
{
$students = Student::search($search)->paginate(15);
//$students = Student::with('city')->paginate(15);
}
elseif (($course) && ($year))
{
$students = Student::whereHas('course_id',$course)->orWhere('year_of_admission',$year)->paginate(15);
}
and view
<form action="" method="get" class="form-inline">
<div class="form-group">
<select id="course" class="form-control" name="course" >
<option value="">---Select Course</option>
@foreach($courses as $key=>$value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</select>
<select id="year" name="year" class="form-control">
<option value="">---Select year</option>
@foreach($yearoptions as $yearoption)
<option value="{{ $yearoption->year_count }}">{{ $yearoption->year_count }}</option>
@endforeach
</select>
</div>
<button type="submit">Submit</button>
</form>
Please or to participate in this conversation.