Home » Laravel Ajax Autocomplete Search Example

Laravel Ajax Autocomplete Search Example

Today, We want to share with you Laravel Ajax Autocomplete Search Example.In this post we will show you laravel 5.7 autocomplete search from database, hear for Laravel autocomplete search with typeahead.js we will give you demo and example for implement.In this post, we will learn about Ajax Autocomplete Textbox in Laravel using JQuery with an example.

Laravel Ajax Autocomplete Search Example

There are the Following The simple About Laravel Ajax Autocomplete Search Example Full Information With Example and source code.

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

Step 1 : Create Mysql table

make apps_members table in our mysql database

Read Also:  Remove # from URL VueJS Example

Table structure for table `apps_members`

CREATE TABLE `apps_members` (
  `id` int(11) NOT NULL,
  `member_code` varchar(2) NOT NULL DEFAULT '',
  `member_name` varchar(100) NOT NULL DEFAULT ''

Sample data for table `apps_members`

INSERT INTO `apps_members` (`id`, `member_code`, `member_name`) VALUES
(1, 'jd', 'jaydeep Gondaliya'),
(2, 'KS', 'Krunal Sisodariya'),
(3, 'AK', 'Ankit Kathiriya'),
(4, 'DD', 'Dhaval Dave'),
(1000, 'CD', 'Chirag Dethariya');

-- Indexes for table `apps_members`
ALTER TABLE `apps_members`
-- AUTO_INCREMENT for table `apps_members`
ALTER TABLE `apps_members`

Step 2: Define Laravel Controller

Create Ajax Autocomplete Laravel controller for handle GET http request

php artisan make:controller SuggestionController



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;

class SuggestionController extends Controller
    //for create Laravel controller - php artisan make:controller SuggestionController

    function index()
     return view('suggestion');

    function getData(Request $request)
      $query = $request->get('query');
      $data = DB::table('apps_members')
        ->where('member_name', 'LIKE', "%{$query}%")
      $suggestion_output = '<ul class="dropdown-menu pakainfo" style="display:block; position:relative">';
      foreach($data as $row)
       $suggestion_output .= '
       <li><a href="#">'.$row->member_name.'</a></li>
      $suggestion_output .= '</ul>';
      echo $suggestion_output;


Step 3: Crate Laravel Blade View File


<!DOCTYPE html>
  <title>laravel 5.7 autocomplete search from database - pakainfo.com</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style type="text/css">
    margin:0 auto;
  <hr />
  <div class="pakainfo container box">
   <h3 align="center">Laravel 5.7 autocomplete typeahead search example from scratch</h3><br />
   <div class="form-group">
    <input type="text" name="member_name" id="member_name" class="form-control input-lg" placeholder="Enter Member Name" />
    <div id="memberList">
   {{ csrf_field() }}


        var query = $(this).val();
        if(query != '')
         var _token = $('input[name="_token"]').val();
          url:"{{ route('suggestion.getData') }}",
          data:{query:query, _token:_token},

    $(document).on('click', 'li', function(){  


Step 4: Include Route Methods and Controller


Route::get('/', function () {
    return view('home');

Route::get('/suggestion', '[email protected]');
Route::post('/suggestion/getData', '[email protected]')->name('suggestion.getData');

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  Laravel Ajax Autocomplete Search Box Example


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

I hope you get an idea about Laravel Ajax Autocomplete Search Example.
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.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel autocomplete typeahead search example
  2. Read Also:  PHP Laravel Autocomplete search from Database Example
  3. Read Also:  Laravel 5.8 Autocomplete Textbox Fields Using jQuery
  4. Read Also:  Laravel Import CSV File into MySQL Example
  5. Read Also:  Convert object to Array in PHP Example
  6. Read Also:  Laravel AJAX Live Autocomplete Search from Database
  7. Read Also:  vue.js Get Current DateTime Example
  8. Read Also:  sql subquery example
  9. Read Also:  Angularjs Check duplicated value in array
  10. Read Also:  Clear All Cache From Laravel project 5.7

Leave a Comment

Your email address will not be published. Required fields are marked *