问题
I'm trying to do the implementation of this pure PHP project (Re-write pure PHP code in Laravel-5.1 format) in Laravel-5.1 version, and I'm yet to get what needs to be done right. Bootstrap Typeahead is not effected. I would appreciate being pointed to what I'm to do right.
This is the blade form:
{!! Form::open(array('url' => 'created-products', 'method' => 'post'), array('id'=>'createproduct')) !!}
{!! Form::token() !!}
<link href="{!! asset('bootstrap/css/bootstrap.css') !!}" media="all" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="style.css">
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<p>{!! Form::select('countries', array('-1' => 'Select a Country') + $listedCountries) !!} </p>
<p>{!! Form::text('typeahead', null, array('class'=>'well', 'placeholder'=>'enter your state'), array('id'=>'selectedCompanyHiddenId', 'data-provider'=>'typeahead')) !!}</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="{!! asset('bootstrap/js/bootstrap.js') !!}" media="all" rel="stylesheet" />
<script>
$(function(){
$('#typeahead').typeahead({
source: function(query, process){
$.ajax({
url: 'UserAddressController.php?SelectLocationPlaces',
type: 'POST',
data: 'query=' +query,
dataType: 'JSON',
async: true,
success: function(data){
process(data);
}
});
}
});
});
</script>
{!! Form::close() !!}
This is the controller:
public function create()
{
$listedCountries = $this->showListedCountries();
return view('useraddress.create')
->with('listedCountries', $listedCountries)
->with('returnedLocationPlaces', $this->SelectLocationPlaces());
}
The method returning the records:
public function SelectLocationPlaces()
{
if(isset($_POST['query']))
{
$query = $_POST['query'];
$locationPlaces = LocationPlaces::where('name', 'like', "%{$query}%")->toArray();
return json_encode($locationPlaces);
}
}
来源:https://stackoverflow.com/questions/34679066/using-bootstrap-typeahead-in-laravel-5-1