0

I have 2 databases in my Laravel 5.7 app, and I would like to add a typeahead functionality with one of them.

It is the first time I use it, so I don't really know how to do it.

I'm following the instructions here: https://itsolutionstuff.com/post/laravel-57-autocomplete-search-from-database-using-typeahead-jsexample.html

dawn
  • 1,327
  • 6
  • 19
  • 39

1 Answers1

0

I have used typeahead in my application. Hope this would help you.

$(document).ready(function(){   
    $.ajax(
    {
        type : 'GET',
        url: base_url+"/getrelateduser",
        success: function (data)
        {
            // Defining the local dataset
            var relateduser = data;

            // Constructing the suggestion engine
            var relateduser = new Bloodhound({
                datumTokenizer: Bloodhound.tokenizers.whitespace,
                queryTokenizer: Bloodhound.tokenizers.whitespace,
                local: relateduser
            });
            $('.sendleads').typeahead({
                hint: true,
                highlight: true, /* Enable substring highlighting */
                minLength: 3, /* Specify minimum characters required for showing result */
            },
            {
                name: 'relateduser',
                source: relateduser
            });
        }
    });
});

Here the url "/getrelateduser" will return all the emails of users in the users table. Let me know if you have more queries.

Kayal
  • 21
  • 6