2017-06-12 3 views
0

Ich versuche Daten von einer ID aus einer Datenbanktabelle zu erhalten und in einer Datentabelle anzuzeigen.Abfrage in Controller von ID mit jQuery

Mit jQuery, ich habe die nächste Funktion:

var info = function(tbody, table){ 
$(tbody).on("click","a[id=ButtonMas]", function(){ 
     if(table.row(this).child.isShown()){ 
      var data = table.row(this).data(); 
     }else{ 
      var data = table.row($(this).parents("tr")).data(); 
     } 

     var pc = data["id"]; 
     route = "/historico/"+pc+""; 

     $('#ModalInfoEquipos').modal('show'); 

     var dt_historico = $('#t_historico').DataTable({ 
      "ajax": { 
       "url": route, 
       "dataSrc": "" 
       }, 
      "columns": [ 
       { "data": "created_at" }, 
       { "data": "estado" }, 
       { "data": "ubicacion" }, 
       { "data": "empleado" }, 
       { "data": "f_asignacion" },     ], 
      "language": { 
        "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Spanish.json" 
       }, 
      "scrollX": true, 
     }); 
}); 
} 

In meinem Controller habe ich den nächsten Index implementiert:

public function index(Request $request, $id) 
{ 
    if ($request->ajax()) { 
     $historico = HistoricoEquipos::Consulta($id); 
     return response()->json($historico); 
    } 
    return view('historico.index'); 
} 

Aber mein response-> json get leer ist eine falsche .

In meinem Modell habe ich meine Funktion Consulta umgesetzt:

public static function Consulta($id){ 
    return DB::table('historico_equipos') 
     ->select('historico_equipos.*') 
     ->where('id_equipo', $id) 
     ->get(); 
} 

ich die nächste Anfrage erhalten und müssen den ersten Wert (1) für meine Abfrage nehmen:

Request - Chrome Inspector

Wo ist der Fehler?

Danke.

Antwort

0

Ich habe einen Fehler in meiner Routendefinition.

Ich habe dies geändert:

Route::resource('historico','HistoricoEquiposController') 

Um dies:

Route::resource('historico','HistoricoEquiposController', ['except' =>['index']]); 
Route::get('historico/{historico}', '[email protected]')->name('historico.index'); 

Mit Hilfe von @Shaz. Vielen Dank.