Created
November 29, 2016 22:15
-
-
Save talha08/453baea0c7e72907432ef14ffe9dde0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
................................. | |
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