I am trying to extract data from a table from an ID and display it with a datatable.
By jquery, I have the following function:
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 my controller, I have defined the following index:
public function index(Request $request, $id)
{
if ($request->ajax()) {
$historico = HistoricoEquipos::Consulta($id);
return response()->json($historico);
}
return view('historico.index');
}
But it returns a json
empty and incorrect.
In my model, I have defined my Query function:
public static function Consulta($id){
return DB::table('historico_equipos')
->select('historico_equipos.*')
->where('id_equipo', $id)
->get();
}
I receive the following request
and I need the first value (1) to be able to use it in my query and get the correct data:
Where do I have the error?
Thank you.