Laravel autocomplete search

Laravel autocomplete search


Route::get('search', 'SearchController@autocomplete');



namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;

class SearchController extends Controller
    public function autocomplete(Request $request)
          $query = $request->get('query');
          $results = User::where('name', 'LIKE', '%'. $query. '%')->get();
          return response()->json($results);


/*inside head tag of layout*/
<link rel="stylesheet" href="[email protected]/dist/css/bootstrap.min.css" />

/*at the closing body tag of layout*/
<script src="//"></script>

<script src=""></script>

<script type="text/javascript">
    var route = "{{ url('search') }}";
        source: function (query, process) {
            return $.get(route, {
                query: query
            }, function (data) {
                return process(data);
/*at the closing body tag of layout*/


/*inside view blade template*/
<div class="container mt-5">
	<div classs="form-group">
	    <input type="text" id="search" name="search" placeholder="Search" class="form-control" />

click for more laravel codes, read in detail about laravel Queries