I am trying to create a dynamic select with ajax, when selecting a role, users with the selected role should be displayed.
The script that I am using is the following
<script type="text/javascript">
$(document).ready(function(){
$('#sucursal').on('change', function(e){
console.log(e);
var id = e.target.value;
$.ajax({
type: 'get',
url: 'ajax'+id,
scuccess: function(data){
console.log(data);
}
});
});
});
</script>
My route is as follows
Route::get('ajax/{id}', ['as'=>'ajax','uses'=>'RecepcionController@ajax']);
And in my controller I have the following
public function ajax($id) {
$id = $id;
$nombre = User::where('role_id','=',$id)->get();
return response()->json($nombre);
}