Laravel 5 Autocomplete using Bootstrap Typeahead JS Example with Demo

Laravel 5 Autocomplete using Bootstrap Typeahead JS Example with Demo

In this post we will give you information about Laravel 5 Autocomplete using Bootstrap Typeahead JS Example with Demo. Hear we will give you detail about Laravel 5 Autocomplete using Bootstrap Typeahead JS Example with DemoAnd how to use it also give you demo for it if it is necessary.

Autocomplete is must if you are dealing with big data table, like you have products table and thousands of records so it’s not possible to give drop-down box, but it is better if we use Autocomplete instead of select box.

In this example i use Bootstrap Typeahead JS plugin for auto-complete, Typeahead.js plugin provide good layout using bootstrap so it pretty good. You can implement autocomlete in your laravel application just following few step. After this example finish you will find out layout as bellow:


Step 1: Create items table and module

In First step we have to create migration for items table using Laravel 5 php artisan command, so first fire bellow command:

php artisan make:migration create_items_table

After this command you will find one file in following path database/migrations and you have to put bellow code in your migration file for create items table.

use IlluminateDatabaseSchemaBlueprint;

use IlluminateDatabaseMigrationsMigration;

class CreateItemsTable extends Migration


public function up()


Schema::create('items', function (Blueprint $table) {







public function down()





After craete “items” table you should craete Item model for items, so first create file in this path app/Item.php and put bellow content in item.php file:


namespace App;

use IlluminateDatabaseEloquentModel;

use DB;

class Item extends Model


public $fillable = ['title','description'];


Step 2: Add Route

We need to add two route one for search view call and another for autocomplete so add two route in your routes.php file:




Also see:Autocomplete with images and custom html code in Jquery UI?

Step 3: Create controller

Ok, now we should create new controller as SearchController in this path app/Http/Controllers/SearchController.php. this controller will manage search page and autocoplete json, so put bellow content in controller file:


namespace AppHttpControllers;

use IlluminateHttpRequest;

use AppHttpControllersController;

use AppItem;

class SearchController extends Controller



* Display a listing of the resource.


* @return IlluminateHttpResponse


public function search()


return view('search');



* Show the form for creating a new resource.


* @return IlluminateHttpResponse


public function autocomplete(Request $request)


$data = Item::select("title as name")->where("title","LIKE","%{$request->input('query')}%")->get();

return response()->json($data);



Step 4: Create View

In this step we have create search.blade.php file in resources directory.


Also see:Laravel 5.7 Autocomplete Search from Database using Typeahead JS



<link href="" rel="stylesheet">

<script src=""></script>

<script src=""></script>

<div >

<h1>Laravel 5 Autocomplete using Bootstrap Typeahead JS</h1>

<input style="margin:0px auto;width:300px;" type="text">


<script type="text/javascript">

var path = "{{ route('autocomplete') }}";


source: function (query, process) {

return $.get(path, { query: query }, function (data) {

return process(data);






Hope this code and post will helped you for implement Laravel 5 Autocomplete using Bootstrap Typeahead JS Example with Demo. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Exit mobile version