Tagged: laravel autocomplete from database

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

<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

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.

Laravel autocomplete typeahead search example 0

Laravel autocomplete typeahead search example

Today, We want to share with you Laravel autocomplete typeahead search example.In this post we will show you Laravel Search with Laravel and Typeahead.js, hear for Laravel autocomplete search with typeahead.js 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 JS with an example.

Laravel autocomplete typeahead search example

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

As I will cover this Post with live Working example to develop Laravel 5 Autocomplete using Bootstrap Typeahead JS, so the some major files and Directory structures for this example is following below.

HTML Interface

index.php

<?php
include("include/header.php");
?>
<h3>Student Management System</h3>
<div class="well bs-component">
<h3>laravel autocomplete search bootstrap</h3>
    <div class="row">
        <div class="col-md-12">
            <div style="text-align: center;">
                <div style="margin-top:5%;margin-bottom:9%;">
                    <h1>We are here to help!</h1>
                    <br/>
                    <div class="col-lg-3"><label for="name" class="control-label"></label></div>
                    <div class="col-lg-7">
                        <div id='autosearch-box'>
                            <form action="<?php echo $base_url; ?>create-student.php" class="form-horizontal" id='form'>
                                <input id='autosearch' class="typeahead" autocomplete="off" name='autosearch' placeholder='Go ahead, ask us anything' type='text'/>
                                <button id='autosearch-button' type='submit'>                     
                                <span><a href="<?php echo $base_url; ?>create-student.php" class="btn btn-raised btn-info" style="margin:0px;">Create Student Anyway</a></span>
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	<a href="https://pakainfo.com/" target="_blank" alt="pakainfo" title="pakainfo">Free Download Example - Pakainfo.com</a>
</div> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
    <script src="https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script>
    <script>
    var subject_name = '<?php echo $_SESSION["subject_name"]; ?>';
        $(document).ready(function() {
            var bloodhound = new Bloodhound({
                datumTokenizer: Bloodhound.tokenizers.whitespace,
                queryTokenizer: Bloodhound.tokenizers.whitespace,
                remote: {

                    url: '<?php echo $api_url; ?>liveautosearch?subject_name=' + subject_name + '&query=%QUERY%',
                    wildcard: '%QUERY%'
                },
            });
            //console.log(bloodhound);
            $('#autosearch').typeahead({
                hint: false,
                highlight: true,
                minLength: 1
            }, {
                name: 'schools',
                source: bloodhound,
                display: function(data) {
                    return data.title;  //Input value to be set when you select a suggestion. 
                },
                templates: {
                    empty: [

                        '<div class="list-group-item tt-suggestion tt-selectable">Nothing found.</div></div>'
                    ],
                    header: [
                        '<div class="list-group autosearch-results-dropdown">'
                    ],
                    suggestion: function(data) {
                        //console.log(data);
                    return '<div style="font-weight:normal;font-size: 14px;" class="list-group-item"><a href="'+ data.destination_url +'" target="_blank">' + data.title + '</a></div></div>'
                    }
                }
            });
        });

$(document).on('click', '#autosearch-button', function () {
    var set_input_msg = $("#autosearch").val();
    localStorage.setItem("select_subject", set_input_msg);
});
    </script>
<style>
/* suggestion box css */

form .dropdown-menu > li a {
    display: block !important;
    height: 100% !important;
    color: inherit !important;
    text-decoration: none !important;
    padding: 8px 20px;
    font-size: 14px;
}

form .dropdown-menu>.active>a, .dropdown-menu>.active>a:focus, .dropdown-menu>.active>a:hover {
    background-color: #eee !important;
}

form .dropdown-menu{
width: 100%;
}

#autosearch-box {
position: relative;
width: 100%;
margin: 0;
}

#autosearch-form 
{
height: 40px;
border: 1px solid #999;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
background-color: #fff;
overflow: hidden;
}

#autosearch-text 
{
font-size: 14px;
color: #ddd;
border-width: 0;
background: transparent;
}

#autosearch-box input[type="text"]
{
width: 100%;
padding: 11px 0 12px 1em;
color: #333;
outline: none;
}

#autosearch-button {
position: absolute;
top: 0;
right: 0;
font-size: 14px;
color: #fff;
text-align: center;
line-height: 43px;
border-width: 0;
background-color: /*#003c88*/ #1e4e72;
color: rgba(255,255,255, 0.84);
-webkit-border-radius: 0px 5px 5px 0px;
-moz-border-radius: 0px 5px 5px 0px;
border-radius: 0px 5px 5px 0px;
cursor: pointer;
}

#autosearch{
    border-radius:0;
    -webkit-box-shadow: 2px 3px 0px -2px #3d3d3d;
    padding:10px;
    border:0px;
    outline: none;
    border-top: 1px solid #3d3d3d;
  border-left: 1px solid #3d3d3d;
  border-right: 1px solid #3d3d3d;
  border-bottom: 1px solid #3d3d3d;
}
#autosearch:hover{
    -webkit-box-shadow: 3px 6px 7px -3px #3d3d3d;
}
.twitter-typeahead{
    display: block !important;
}
.list-group {
    margin-bottom: 0px !important;
}
.twitter-typeahead, .tt-hint, .tt-input, .tt-menu { width: 100%; }
.list-group-item { 
text-align: left;
}
</style>
<?php
include("include/footer.php");
?>

Laravel File – Routing

routes/api.php

<?php

use Illuminate\Http\Request;

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');

Route::get('liveautosearch','API\[email protected]');

app/http/controllers/API/StudentController.php

Public function liveautosearch(Request $request)
{ 
	$term = $request->get('query');
	$subject_name = trim($request->get('subject_name'));
	$id =DB::table('subjects')->where('name', $subject_name)->first()->id;
	return DB::table('schools')->where([['title', 'LIKE', '%'.$term.'%'],['subject_id', '=', $id]])->get();

}

Angular 6 CRUD Operations Application Tutorials

Read :

Related Search : laravel autocomplete search bootstrap, laravel autocomplete jquery, laravel jquery autocomplete json, laravel autocomplete typeahead, laravel autocomplete from database, autocomplete typeahead bootstrap laravel,Laravel autocomplete search with typeahead.js,Laravel And JqueryUI’s Autocomplete,Laravel 5.7 Autocomplete Search from Database using Typeahead JS,Laravel 5.7 Autocomplete using Bootstrap Typeahead JS Example,Search with Laravel and Typeahead.js,Laravel 5.7 Autocomplete using Bootstrap Typeahead JS Example with Demo

Summary

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

I hope you get an idea about Laravel autocomplete typeahead 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 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.

PHP Laravel Autocomplete search from Database Example 0

PHP Laravel Autocomplete search from Database Example Tutorial

Today, We want to share with you PHP Laravel Autocomplete search from Database Example Tutorial.In this post we will show you Autocomplete Textbox using jQuery, PHP, Laravel and MySQL, hear for Laravel Ajax Autocomplete Search from Database Example we will give you demo and example for implement.In this post, we will learn about Laravel Autocomplete using Bootstrap Typeahead JS Example with Demo with an example.

PHP Laravel Autocomplete search from Database Example Tutorial

There are the Following The simple About PHP Laravel Autocomplete search from Database Example Tutorial Full Information With Example and source code.

As I will cover this Post with live Working example to develop Manual Laravel Autocomplete search from Database, so the Laravel Ajax Autocomplete Search from Database for this example is following below.

  • Define routes
  • Set up controllers
  • changes the view
  • Step 1 : Create a Laravel routes

    first of all toy need to Define a Laravel route in main file web.php to showing New HTML search form,

    route/web.php

    Route::view('/find', 'find');
    

    Include a Laravel search route

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

    Step 2 : Set up controllers

    make a Laravel LiveFindController

    LiveFindController

    public function searchMembers(Request $request)
    {
        return Member::where('name', 'LIKE', '%'.$request->q.'%')->get();
    }
    

    Step 3 :changes the view Blade files

    Path : resources/views/find.blade.php

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="www.pakainfo.com">
        <meta name="author" content="sapnesh_naik">
        <title>Autocomplete Search Bar in Laravel with Typehead.js - Laravel Search Autocomplete tutorial</title>
        <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
        <link href="{{asset('starter-template.css')}}" rel="stylesheet">
         <style>
            .twitter-typeahead,
            .tt-hint,
            .tt-input,
            .tt-menu{
                width: auto ! important;
                font-weight: normal;
    
            }
         </style>
      </head>
      <body>
    
        <div class="pakainfo container">
          <div class="starter-template pakainfo" style="align-text:right">
            <h1>Laravel Search Autocomplete - Laravel Autocomplete Search from database using jQuery</h1>
            <p>Laravel Autocomplete using Bootstrap Typeahead JS Example with Demo</p>
            <br>
            <input type="text" id="find" placeholder="Type to find members" autocomplete="off" >
          </div>
    
        </div>
        <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
        <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    
    
        <script src="//twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script>
        <script>
            $(document).ready(function() {
                var bloodhound = new Bloodhound({
                    datumTokenizer: Bloodhound.tokenizers.whitespace,
                    queryTokenizer: Bloodhound.tokenizers.whitespace,
                    remote: {
                        url: '/member/find?q=%QUERY%',
                        wildcard: '%QUERY%'
                    },
                });
    
                $('#find').typeahead({
                    hint: true,
                    highlight: true,
                    minLength: 1
                }, {
                    name: 'members',
                    source: bloodhound,
                    display: function(data) {
                        return data.name  //here HTML Input value one by one to be changes and set when you choose a suggestion for Laravel autocomplete search with typeahead.js.
                    },
                    templates: {
                        empty: [
                            '<div class="pakainfo list-group find-results-dropdown"><div class="pakainfo list-group-item">Nothing found.</div></div>'
                        ],
                        header: [
                            '<div class="pakainfo list-group find-results-dropdown">'
                        ],
                        suggestion: function(data) {
                        return '<div style="font-weight:normal; margin-top:-15px ! important;" class="pakainfo list-group-item">' + data.name + '</div></div>'
                        }
                    }
                });
            });
        </script>
    
      </body>
    </html>
    

    Angular 6 CRUD Operations Application Tutorials

    Read :

    Related Search : laravel autocomplete search bootstrap, laravel autocomplete jquery, laravel jquery autocomplete json, laravel autocomplete typeahead, laravel autocomplete from database, autocomplete typeahead bootstrap laravel

    Summary

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

    I hope you get an idea about PHP Laravel Autocomplete search from Database Example Tutorial.
    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.