Laravel Autocomplete Live Search from database

Today, We want to share with you Laravel Autocomplete Live Search from database using jQuery.In this post we will show you Manual Laravel Autocomplete search from Database, hear for Laravel 5.7 Autocomplete Search from Database using Typeahead JS we will give you demo and example for implement.In this post, we will learn about Laravel Bootstrap Typeahead Autocomplete Search from Database with an example.

Laravel Autocomplete Live Search from database using jQuery

There are the Following The simple About Laravel Autocomplete Live Search from database using jQuery Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 5.7 autocomplete search with typeahead.js, so the laravel 5.7 autocomplete from database for this example is following below.

Also Read :  Laravel Ajax Autocomplete Search Box Example

Step 1:- Create Laravel the migration

command line and type

php artisan make:model tbl_data -m

structure of my migration

public function up()
{
	Schema::create('products', function (Blueprint $table) {
		$table->increments('id');
		$table->string('title');
		$table->string('slug');
		$table->timestamps();
	});
}

Step 2 : create a view resources/views

resources/views/autocomplete.blade.php

<html>
<head>
    <title>
       Laravel 5.7 jQUery Auto Complete - Pakainfo.com</title>
   <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
   <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
   <style>

       * {
        margin: 0px auto; !important /* Aligning all the data to center */
    }
</style>

</head>
<body>
<h3>Laravel 5.7 Autocomplete Search from Database using Typeahead JS Example</h3>
    <div class="container" style="margin-top: 10px;">
        <div align="center">
            <div class="row">
                <div class="col-md-6">
                    <div class="row">
                        <div class="col-md-12">
                            <form action="">
                                <div class="form-group">
                                    <div class="ui-widget">
                                        <label for="">Search for Anything</label>
                                        <input id="searchString" type="text" name="search_string" placeholder="Enter Search String" class="form-control" />
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </center>
    </div>

    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
</body>
</html>

jQuery Code

Also Read :  Laravel autocomplete typeahead search example

Laravel Autocomplete Search from database using jQuery Source code

$( function() {
          $( "#searchString" ).autocomplete({
            //html : html,
            source: "display-search-queries",
            minLength: 1,
            select:function(e,ui) { 
                location.href = ui.item.link;
            }
        } );
      } );

Define a Laravel Route

Route::get('/','[email protected]');

Route::get('display-search-queries','[email protected]');

Step 3: Create Laravel Controller

ProductController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Response;
use DB;

class ProductController extends Controller
{
    public function index() {
        return view('autocomplete');
    }

    public function autoCompleteSearch(Request $request) {
        $querystr = $request->get('querystr');
    	$data = DB::table('products')->where("title","LIKE","%$querystr%")->select('title as value','slug as link')->get();
        return response()->json($data);
    }
}

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel Autocomplete Live Search from database using jQuery.
I would like to have feedback on my Pakainfo.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.

Gondaliya Jaydeep

Hi, I’m Jaydeep Gondaliya, PHP developer.Pakainfo.com is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development.Any visitors of this site are free to browse our tutorials, live demos, Examples and download scripts.If you have a project that you want to get started, launch quickly, contact me. Email : [email protected]