Skip to content

Instantly share code, notes, and snippets.

@talha08
Created November 29, 2016 22:15
Show Gist options
  • Save talha08/453baea0c7e72907432ef14ffe9dde0f to your computer and use it in GitHub Desktop.
Save talha08/453baea0c7e72907432ef14ffe9dde0f to your computer and use it in GitHub Desktop.
.................................
Function
.................................
Route::get('company/search', function(){
$data = Input::get('term');
$company = App\Company::where('name', 'LIKE', $data.'%' )->get();
foreach ($company as $query)
{
$results[] = [ 'id' => $query->id, 'value' => $query->name];
}
return Response::json($results);
});
.................................
View
.................................
{!!Form::text('name', null,array('class' => 'form-control','placeholder' => 'Company Name', 'id'=>'autocomplete','required'))!!}
.................................
Script
.................................
//use This two CDN
<link href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" rel="Stylesheet"></link>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" ></script>
<script type="text/javascript">
jQuery(document).ready(function() {
$(function()
{
$( "#autocomplete" ).autocomplete({
source: "{!! URL('company/search') !!}",
minLength: 1,
select: function(event, ui) {
$('#autocomplete').val(ui.item.value);
}
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment