如何在laravel顶部删除最后插入的记录

时间:2017-03-24 05:29:57

标签: laravel-5

public function listStudentData() {

    $list = Student::all()->sortByDesc("first_name");
    return Datatables::of($list)
                    ->make(true);

}

这不起作用!!

2 个答案:

答案 0 :(得分:0)

取决于您是要使用id还是created_at时间戳:

$students = Student::orderBy('id', 'desc')->get();

// or

$students = Student::orderBy('created_at', 'desc')->get();

答案 1 :(得分:0)

您始终可以在查询中使用latest():

    jQuery(document).ready(function(){

    jQuery('#shopping-cart-table')
     .on(
          'change',
          'input[name$="[qty]"]',
           function(){
            var form = jQuery(jQuery(this).closest('form'));

             // we'll extract the action and method attributes out of the form

              // kick off an ajax request using the form's action and method,
        // with the form data as payload
        jQuery.ajax({
            url: form.attr('action'),
            method: form.attr('method'),
            data: form.serializeArray()
        });
    }
);