Tagged: laravel 5.7 autocomplete

Laravel Autocomplete Live Search from database 0

Laravel Autocomplete Live Search from database using jQuery

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.

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


    <title>
       Laravel 5.7 jQUery Auto Complete - Pakainfo.com</title>
   
   
   
   

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




<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>
                                        
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        
    </div>

    
    
    
    


jQuery Code

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

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.

Laravel Ajax Autocomplete Search Example 0

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

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 ''
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

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`
  ADD PRIMARY KEY (`id`);
  
  
 --
-- AUTO_INCREMENT for table `apps_members`
--
ALTER TABLE `apps_members`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=246; 

Step 2: Define Laravel Controller

Create Ajax Autocomplete Laravel controller for handle GET http request

php artisan make:controller SuggestionController

app/Http/Controllers/SuggestionController.php

<?php

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)
    {
     if($request->get('query'))
     {
      $query = $request->get('query');
      $data = DB::table('apps_members')
        ->where('member_name', 'LIKE', "%{$query}%")
        ->get();
      $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

resources/views/suggestion.blade.php

<!DOCTYPE html>
<html>
 <head>
  <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">
   .box{
    width:800px;
    margin:0 auto;
   }
  </style>
 </head>
 <body>
  <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">
    </div>
   </div>
   {{ csrf_field() }}
  </div>
 </body>
</html>

<script>
$(document).ready(function(){

 $('#member_name').keyup(function(){ 
        var query = $(this).val();
        if(query != '')
        {
         var _token = $('input[name="_token"]').val();
         $.ajax({
          url:"{{ route('suggestion.getData') }}",
          method:"POST",
          data:{query:query, _token:_token},
          success:function(data){
           $('#memberList').fadeIn();  
                    $('#memberList').html(data);
          }
         });
        }
    });

    $(document).on('click', 'li', function(){  
        $('#member_name').val($(this).text());  
        $('#memberList').fadeOut();  
    });  

});
</script>

Step 4: Include Route Methods and Controller

routes/web.php

<?php
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 :

Summary

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.

Laravel AJAX Live Autocomplete Search from Database 0

Laravel AJAX Live Autocomplete Search from Database Example

Today, We want to share with you Laravel AJAX Live Autocomplete Search from Database Example.In this post we will show you jQuery Autocomplete Tutorial with Laravel 5.7 and MySQL, hear for Laravel 5.7 Ajax Autocomplete Search from Database Example we will give you demo and example for implement.In this post, we will learn about Laravel 5.7 Autocomplete Search From Database Using Typeahead Tutorial Example with an example.

Laravel AJAX Live Autocomplete Search from Database Example

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

As I will cover this Post with live Working example to develop Autocomplete Textbox using Laravel 5.7, PHP and MySQL, so the some major files and Directory structures for this example is following below.

  • Setup Laravel 5.7 Project
  • Settings .env files SQL Database
  • build Laravel 5.7 Model and Migration Database
  • make Laravel 5.7 a HTML View File
  • make Laravel 5.7 one controller
  • Laravel 5.7 Route
  • Store data Laravel 5.7 to the database
  • make an index page Laravel 5.7 Search the data
  • Include jQuery in the view Index File

Laravel 5.7 Autocomplete Search From Database Using Typeahead Tutorial Example

#1: Setup Laravel 5.7 Application

Install Laravel 5.7 Project step by step

composer create-project --prefer-dist laravel/laravel liveautocompletebox

Step #2: Settings SQL Database

.env files on root

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=liveautocompletebox
DB_USERNAME=root
DB_PASSWORD=

Step #3: build Laravel 5.7 Model and Migration Database

Laravel 5.7 Model and Migration files

php artisan make:model Member -m 

make the member.php file as well as create a create_members_table.php

//Ajax Autocomplete Textbox in Laravel 5.7 using jQuery
public function up()
    {
        Schema::create('members', function (Blueprint $table) {
            $table->increments('id');
            $table->string('membername');
            $table->timestamps();
        });
    }

Database >> member table.

php artisan migrate

Step #4: Make a Laravel 5.7 View File

resources/views/createmember.blade.php

<!-- createmember.blade.php for Ajax Autocomplete Textbox in Laravel 5.7 using jQuery -->

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Laravel 5.7 Autocomplete Search From Database Tutorial With Example</title>
    <link rel="stylesheet" href="{{asset('css/app.css')}}">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  </head>
  <body>
    <div class="container">
      <h2>Laravel 5.7 AJAX Live Autocomplete Search from Database Example</h2><br/>
      <form method="post" action="{{url('store')}}">
        @csrf
        <div class="row">
          <div class="col-md-4"></div>
          <div class="form-group col-md-4">
            <label for="Name">Member Name:</label>
            <input type="text" class="form-control" name="membername">
          </div>
        </div>
        <div class="pakainfo row">
          <div class="col-md-4"></div>
          <div class="form-group col-md-4">
            <button type="submit" class="btn btn-success">Add Member</button>
          </div>
        </div>
      </form>
   </div>
  </body>
</html>

Step #5: Make Laravel 5.7 controller

create Laravel Controller as well as Model

php artisan make:controller MemberController

MemberController.php

//MemberController.php
//Ajax Autocomplete Textbox in Laravel 5.7 using jQuery

public function create()
    {
        return view('createmember');
    }

Step #6: Laravel Route

web.php

//web.php

Route::get('createmember','[email protected]');
Route::post('store','[email protected]');
Route::get('createmember/index','[email protected]');
Route::get('search','[email protected]');

Run Laravel 5.7 Project -> Ajax Autocomplete Textbox in Laravel 5.7 using jQuery

php artisan serve

Step #7: Store data Laravel 5.7 to the database

MemberController.php

//MemberController.php

public function store(Request $request)
    {
        $member = new \App\Member();
        $member->membername=$request->get('membername');
        $member->save();
        return redirect('createmember/index')->with('success', 'Member has been added Successfully');
    }

Step #8: Make an index page for Laravel 5.7 Search the data

resources/views/indexmember.blade.php

<!-- indexmember.blade.php -->

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Ajax Autocomplete Textbox in Laravel 5.7 using jQuery</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js"></script></head>
  <body>
    <div class="container">
      <h2>Laravel 5.7 AJAX Live Autocomplete Search from Database Example</h2><br/>
      @if (\Session::has('success'))
      <div class="alert alert-success">
        <p>{{ \Session::get('success') }}</p>
      </div><br />
     @endif
        <div class="row">
          <div class="col-md-4"></div>
          <div class="form-group col-md-4">
            <label for="Search">Search:</label>
            <input type="text" class="form-control" id="search" name="search">
          </div>
        </div>
    </div>
  </body>
</html>

index Methods in MemberController.php

public function index()
    {
        return view('indexmember');
    }

MemberController.php

//MemberController.php

public function result(Request  $request)
    {
        $result=\App\Member::select('membername')->where('membername', 'LIKE', "%{$request->input('query')}%")->get();
        return response()->json($result);
    }

MemberController.php

//MemberController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class MemberController extends Controller
{
    public function create()
    {
        return view('createmember');
    }
    public function store(Request $request)
    {
        $member = new \App\Member();
        $member->membername=$request->get('membername');
        $member->save();
        return redirect('createmember/index')->with('success', 'Member has been added Successfully');
    }
    public function index()
    {
        return view('indexmember');
    }
    public function result(Request  $request)
    {

        $result=\App\Member::select('membername')->where('membername', 'LIKE', "%{$request->input('query')}%")->get();
        return response()->json($result);
    }
}

Step #9: Include jQuery in the Laravel View Index File

indexmember.blade.php

<!-- indexmember.blade.php -->

<script type="text/javascript">


    var path = "{{ url('search') }}";

    $('#search').typeahead({
         minLength: 2,
        source:  function (query, process) {
        return $.get(path, { query: query }, function (data) {
            var memberlist = [];
                data.forEach(function(value){
                    memberlist.push(value.membername);
                });
                return process(memberlist);
            });
        }
    });
    </script>

indexmember.blade.php

<!-- indexmember.blade.php -->

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Laravel 5.7 - Ajax Autocomplete Textbox in Laravel 5.7 using jQuery</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js"></script></head>
  <body>
    <div class="container">
      <h2>Laravel 5.7 AJAX Live Autocomplete Search from Database Example</h2><br/>
      @if (\Session::has('success'))
      <div class="alert alert-success">
        <p>{{ \Session::get('success') }}</p>
      </div><br />
     @endif
        <div class="row">
          <div class="col-md-4"></div>
          <div class="form-group col-md-4">
            <label for="Search">Search:</label>
            <input type="text" class="form-control" id="search" name="search">
          </div>
        </div>
    </div>
    <script type="text/javascript">


    var path = "{{ url('search') }}";

    $('#search').typeahead({
         minLength: 2,
        source:  function (query, process) {
        return $.get(path, { query: query }, function (data) {
            var memberlist = [];
                data.forEach(function(value){
                    memberlist.push(value.membername);
                });
                return process(memberlist);
            });
        }
    });
    </script>
  </body>
</html>

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 5.7 AJAX Live Autocomplete Search from Database 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.