0
votes

How can page through the results? .It With ajax. to bring the data to my view , I want to use paginate () and orderby (), but to put it is in the documentation , it generates error. if I do so : $cita= Cita::orderBy(asc)->paginate(10), I did not bring the data. Excuse the English 'm Mexican .

Controller:

    public function agenda(){
    $cita = Cita::all();       
     return  Response()->json(
            $cita->toArray()
        );
}

Script:

function Carga(){
var tablaDatos = $("#datos");
var route = "http://cmec.app/agenda";

$("#datos").empty();
$.get(route, function(res){
    $(res).each(function(key, value){
        tablaDatos.append(
            "<tr><td>"+value.name+"</td><td>"+value.lastname+"</td><td>"+value.doctor+"</td><td>"+value.fecha+"</td><td>"+value.hora+"</td><td><div class='btn-group btn-group-sm' role='group'><button value="+value.id+" OnClick='Mostrar(this);' class='btn btn-danger'><i class='fa fa-trash-o'></i></button><button value="+value.id+" OnClick='Mostrar(this); ' class='btn btn-primary' data-toggle='modal' data-target='#editar-modal' ><i class='fa fa-pencil-square'></i></button></div></td></tr>");
    });
});}    

Vista:

            <table class="table table-hover">
            <thead>
                <tr>
                    <th>Nombre</th>
                    <th>Apellidos</th>
                    <th>Doctor</th>
                    <th>Fecha</th>
                    <th>Hora</th>
                    <th>Acciones</th>
                </tr>
            </thead>
            <tbody id="datos"></tbody>
        </table>
2
use $cita= Cita::orderBy('asc')->paginate(10) for pagination with orderHitesh Siddhapura
"it generates error" Please post the error message.Jeemusu

2 Answers

0
votes

Use following for you code

Controller

public function agenda(){
    $cita = Cita::orderBy('asc')->paginate(10);       
    return response()->json($cita->toArray());
}

Script

function Carga(){
    var tablaDatos = $("#datos");
    var route = "http://cmec.app/agenda";

    $("#datos").empty();
    $.getJson(route, function(res){
        $(res).each(function(key, value){
            tablaDatos.append(
                "<tr><td>"+value.name+"</td><td>"+value.lastname+"</td><td>"+value.doctor+"</td><td>"+value.fecha+"</td><td>"+value.hora+"</td><td><div class='btn-group btn-group-sm' role='group'><button value="+value.id+" OnClick='Mostrar(this);' class='btn btn-danger'><i class='fa fa-trash-o'></i></button><button value="+value.id+" OnClick='Mostrar(this); ' class='btn btn-primary' data-toggle='modal' data-target='#editar-modal' ><i class='fa fa-pencil-square'></i></button></div></td></tr>");
        });
    });
} 
0
votes

Error :

QueryException in Connection.php line 636:SQLSTATE[42S22]: Column not found: 1054 Unknown column 'asc' in 'order clause' (SQL: select * from `Citas` order by `asc` asc limit 10 offset 0)