I am able to pull data out from my database using laravel and send it back to kendo autocomplete.
The problem I have is that I am getting the error:
Uncaught TypeError: undefined is not a function
I have a feeling that is because the data being returned is in the wrong format i.e.:
{"16159":"United Kingdom of Great Britain and Northern Ireland"}
When it should be somethind like
[{"id": 16159, "name":"United Kingdom of Great Britain and Northern Ireland"}, *other counties...*]
My Laravel code is:
public function getCities() {
$Cities = new Cities;
$cities = $Cities->where('accentName', 'LIKE', '%unite%')->orderBy('accentName', 'asc')->lists('accentName', 'id');
return $cities;
}
And my JS is:
$('input#cityAuto').kendoAutoComplete({
dataTextField: "name",
filter: "contains",
minLength: 3,
dataSource: {
type: "POST",
serverFiltering: true,
transport: {
read: "apply/getCities"
}
}
});
How can I get Laravel to return the JSON string in the way that I want?
You could do that using Response::json()
like below:
public function getCities() {
$Cities = new Cities;
$cities = $Cities->where('accentName', 'LIKE', '%unite%')->orderBy('accentName', 'asc')->lists('accentName', 'id');
// to return json
return Response::json($cities->toArray());
}