dimanche 18 mars 2018

Laravel 5.5 autocomplete method returns a 500 error in one place not another

I have a simple form to get an autocomplete of an author's name from a table of several thousand.

In my simple form I have:

<form>
     <div class="ui-widget">
        <label for="authors">authors: </label>
        <input id="authors" value="">
     </div>
</form>

The javascript is:

<script>
 $(function()
  {
  $( "#authors" ).autocomplete({
  source: "autocompleteAuthors",
  minLength: 3,
  select: function(event, ui) {
    $('#q').val(ui.item.value);
  }
 });
});
</script>

I have a route pointing to a controller:

  Route::get('autocompleteAuthors','AutoCompleteController@authors')->name('autocompleteAuthors');

and a function in the controller:

public function authors()
  {
    $term = Input::get('term');
    $results = array();

    $queries = DB::table('author')
        ->where('name', 'LIKE', '%'.$term.'%')
        ->take(5)->get();

    foreach ($queries as $query)
    {
        $results[] = [ 'id' => $query->id, 'value' => $query->name];
    }
  return Response::json($results);
  }

This works fine.

In a form to edit a quote (part of the edit could be the author) I have the following:

<div class="ui-widget">
     <label for="author" style="width:10%">author:</label>
     <input id="author" name="author" value="" style="width:50%">
</div>

and the javascript is:

  <script>
   $(function()
   {
    $( "#author" ).autocomplete({
    source: "autocompleteAuthors",
    minLength: 3,
    select: function(event, ui) {
    $('#q').val(ui.item.value);
   }
 });
});
</script>

So they are both sending "term" to the same route yet in the second case I get a 500 error.

Can't see any reason for this!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2HI3Isq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire