I'm trying to filter the records from a query using dropdown menus. The idea is to aply the filter when the dropdown menu is changed, so I imagine the solution is to use ajax, but i don't know much about it and how to use it in laravel.
Here is my controller:
public function setSelectTestView()
{
$test = Test::orderBy('updated_at', 'des')->lists('nom', 'id');
$cursos = Curs::orderBy('nom', 'asc')->lists('nom', 'id');
$assignatures = Assignatura::orderBy('nom', 'asc')->lists('nom', 'id');
return View::make('Test.results.result_select_test')
->with(array('test' => $test, 'cursos' => $cursos, 'asg' => $assignatures));
}
and my blade:
<fieldset>
{{ Form::select('curs', $cursos) }}
{{ Form::select('assignatura', $asg) }}
</fieldset>
{{ Form::open(array('action' => array('ResultsController@setSelectTestView'))) }}
</br>
<fieldset>
{{ Form::select('test', $test) }}
</fieldset>
</br><input type="submit" value="Seleccionar"/>
{{ Form::close() }}
What I want is to filter the variable $test by curs and assignatura, like
$test = Test::where('curs_id', $curs_id)->where('assignatura_id', $asg_id);
but doing this in a asynchronous way and applying one filter depending which dropdown menu has changed, but also if the second filter is changed keeping applying the first one (both applied)