Level 51
Try with lowercase
source: {{ url('autocomplete') }}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a form and i try to use jquery autocomplete for get the products data but doesn't work
Here the form:
{!!Form::label('Product')!!}
{!!Form::text('product_id',null,['class'=>'form-control', 'id'=>'product', 'style'=>'-webkit-border-radius: 8px;-moz-border-radius: 8px;border-radius: 8px;'])!!}
Here the jquery:
<script>
$(document).ready(function() {
$("#product").autocomplete({
minLength:2,
autoFocus: true,
source: {{ URL('autocomplete') }}
});
});
</script>
Here the route:
Route::get('autocomplete', 'DishesController@autocomplete');
Here the controller method:
public function autocomplete()
{
$term = $_POST['term'];
$results = array();
$queries = Products::where('name', 'LIKE', '%'.$term.'%')->take(10)->get();
foreach ($queries as $query)
{
$results[] = [ 'id' => $query->id, 'value' => $query->name];
}
return Response::json($results);
}
I would appreciate it if you could help me with this question.
Please or to participate in this conversation.