How to order by using appended attribute in Laravel

后端 未结 5 1054
南旧
南旧 2021-02-13 19:05

I created an appends attribute in Laravel Model, from the code below.

    protected $appends = array(\'total\'=>\'\');

And I set the returne

5条回答
  •  灰色年华
    2021-02-13 19:54

    You can use the sortBy method from collections.

    $products = Product::all();
    $products = $products->sortBy('total');
    

提交回复
热议问题