Tagged: laravel smart search

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 Ajax Autocomplete Search Box Example 0

Laravel Ajax Autocomplete Search Box Example

Today, We want to share with you Laravel Ajax Autocomplete Search Box Example.In this post we will show you Laravel and ajax autocomplete text field, hear for Create Laravel Search Box With Live Results Using AJAX jQuery 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 Ajax Autocomplete Search Box Example

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

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

Setp 1 : Laravel Index Search Form

Laravel HTML Interface for Autocomplete A Search From Database

<input id="findmembers" type="text" placeholder="Enter Tags or Keywords" />

Setp 2 : Include HTML Header Part jQuery.ui.js file

jquery-ui.js and jquery-ui.css files from cdn

<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

Step 3 : Create a Laravel method to Get data from database

app/http/Controller/memberController.php

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
class memberController extends Controller
{
    public function __construct(){}

    Public function suggestion(Request $request){
        $search = $request->get('term');
        $data = DB::table('members')->where("title","LIKE","%$search%")->get();
        foreach ($data as $result)
        {
            $results[] = ['value' => $result->title, 'link' => 'members/'.$result->url];
        }
        return response()->json($results);       
    }
} 	

Step 4 : Laravel(autocomplete Search) Alternative Method()

Public function suggestion(Request $request){
	$search = $request->get('term');
	$data = DB::table('members')->where("title","LIKE","%$search%")->select('title as value','url as link')->get();
	return response()->json($data);       
}

Step 5 : Define Laravel Routes

web/route.php file

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

Step 6 : Laravel Call autocomplete jquery Ajax script

First of all Include jquery and then put this scripts and run Autocomplete A Search From Database In Laravel With Ajax.

<script>
$( "#findmembers" ).autocomplete({
    source: "suggestion",
    minLength: 1,
    select:function(event,ui) { 
        location.href = ui.item.link;
    }
});
</script>

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 Box 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 Autocomplete text field suggestions search using Database 0

Laravel Autocomplete text field suggestions search using Database

Laravel Autocomplete text field suggestions search using Database

Laravel and ajax autocomplete text field Example

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

Create a Products Table and Model

Insert some dummy test data in your Items table or we can use Laravel latest version or more seed classes to create seeding your simple database with dummy data.If we want to write all the laravel seeders then run this win + r and open cmd to command that generate seed and get dir find this pasth file in database/seeds each directory.Laravel Autocomplete text field suggestions search using Database Example

php artisan make:seeder UsersTableSeeder

Simple Add Route and Controller in Laravel

Add these simple two routes file in your dir routes.php file.

app/Http/routes.php

    Route::get('autocomplete',array('as'=>'autocomplete','uses'=>'[email protected]'));
    Route::get('searchajax',array('as'=>'searchajax','uses'=>'[email protected]'));

Now second phase we will create simple laravelAutoCtrl.php in following path here app/Http/Controllers

app/Http/Controllers/laravelAutoCtrl.php

    namespace App\Http\Controllers;
    use Illuminate\Http\Request;
    use App\Http\Controllers\Controller;
    use App\Product;
    class laravelAutoCtrl extends Controller {
        
        public function home(){
            return view('autocomplete.home');
       }
        public function autoComplete(Request $request) {
            $query = $request->get('term','');
            
            $products=Product::where('name','LIKE','%'.$query.'%')->get();
            
            $data=array();
            foreach ($products as $product) {
                    $data[]=array('value'=>$product->name,'id'=>$product->id);
            }
            if(count($data))
                 return $data;
            else
                return ['value'=>'sorry No any Result Found','id'=>''];
        }
        
    }

Create Blade File

Now we will create simple home.blade.php simple file in following path or directory resources/views/autocomplete/ directory.

    @extends('layouts.default')
     
    @section('content')
       <div class="row">
            <div class="col-xs-6 col-sm-6 col-md-6">
                <div class="form-group">
                    
                    {!! Form::text('mys_text', null, array('placeholder' => 'here any put Search Text','class' => 'form-control','id'=>'mys_text')) !!}
                </div>
            </div>
        </div>
        
       <script>
       $(document).ready(function() {
        src = "{{ route('searchajax') }}";
         $("#mys_text").autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: src,
                    dataType: "json",
                    data: {
                        term : request.term
                    },
                    success: function(data) {
                        response(data);
                       
                    }
                });
            },
            minLength: 3,
           
        });
    });
    </script>
    @endsection

Don’t any forget to simple libs add Js and external Css file in your simple master/default layout page.

<link href="jquery.ui.autocomplete.css" rel="stylesheet">
<script src="js/jquery.js"></script>
<script src="js/jquery-ui.min.js"></script>

Example