fredyounan
2/20/2016 - 11:49 AM

autocomplete-search-selection.txt

/*jQuery UI - Laravel 5*/
/*Search Selection*/
$(function() {
    $(".input-search-selection").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: "{{url('sec-menus/menus-by-field')}}",
                dataType: 'json',
                data: {
                   searchValue: $('.input-search-selection').val(),
                   searchField: $('#searchField').val()
                }
            }).success(function(data){
                response(data);
            });
        },
        select: function( event, ui ) {
            console.log(ui.item.value);
        },
        minLength: 2
    });
});


/*controller ej.*/
public function getMenusByField(Request $request)
{
    $data = \DB::table('SecMenus')
        ->select("{$request->searchField} as label")
        ->where($request->searchField, 'LIKE', '%' . $request->searchValue .'%')
        ->get();

    return $data;
}