Today, We want to share with you Laravel Twitter Typeahead integration.In this post we will show you Ajax Autocomplete Textbox in Laravel 5.8, hear for Laravel Bootstrap Typeahead Autocomplete Search from Database we will give you demo and example for implement.In this post, we will learn about Implementing Smart Search with Laravel and Typeahead.js with an example.
Laravel Twitter Typeahead integration
There are the Following The simple About Laravel Twitter Typeahead integration Full Information With Example and source code.
As I will cover this Post with live Working example to develop laravel 5.8 autocomplete search, so the laravel autocomplete search from database for this example is following below.
Twitter Typeahead integration in Laravel
Javascript Source Code
The simple Typeahead Javascript source Code is given below
<!-- Autocomplete using Bootstrap Typeahead Typeahead --> {!! Html::script('js/typeahead.min.js') !!} <script> $(document).ready(function(){ $('input.typeahead').typeahead({ name: 'typeahead', remote:"{{ url('/search/%QUERY') }}", limit : 10, }); }); </script>
HTML Part
simple material good design lite search box
<div style="padding-bottom:0px;" class="mdl-textfield mdl-js-textfield mdl-textfield--expandable"> <label class="mdl-button mdl-js-button mdl-button--icon" for="search-expandable"> <i class="material-icons">search</i> </label> <div class="mdl-textfield__expandable-holder"> <input class="mdl-textfield__input typeahead" type="text" name="search" id="search-expandable" style="width: 300px;"> <label class="mdl-textfield__label" for="search-expandable"></label> </div> </div>
Define a Laravel Route
Route::get('search/{key}','[email protected]') ->where('key','^[\w\d\-\_\. ]+$');
Laravel Controller
And then we create a Laravel the findProducts function source code in ProductsController
public function findProducts($key) { $all_products = Products::where('title', 'like', '%' . $key . '%')->limit(5)->get(); foreach($all_products as $product) { $products[] = $product->title; } return json_encode($products); }
CSS Part
Last step to some create fix design issue with CSS to improve the main Panel
<style> .tt-hint { color: #3d3d3d; } .tt-dropdown-menu { background-color: #FFFFFF; border: 1px solid rgba(0, 0, 0, 0.2); box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); margin-top: 12px; padding: 8px 0; width: 300px; } .tt-suggestion { padding: 3px 20px; } .tt-suggestion.tt-is-under-cursor { background-color: #3d3d3d; color: #FFFFFF; } .tt-suggestion p { margin: 0; } </style>
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Laravel Twitter Typeahead integration.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโt forget to share.