简体   繁体   中英

How to use sortby with paginate in Laravel

Recently, I tried to order data by using appends attribute. From this code and it works.

    $data = $data->sortBy(function($each){
        return $each->total;
    });

Then I want to use it with my old pagination code as below.

    $data = Book::where("type", $type_id)->orderBy("id","desc")->paginate(10);

The way I want is order data by total attribute and then paginate it.

Does anyone know how to solve this?

试试这个[我没有测试]:

 $data = Book::where("type", $type_id)->orderBy("total")->paginate(10);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM