sortBy()文本不起作用

时间:2017-08-18 11:36:18

标签: php laravel sorting

我在Laravel框架中有一个函数解析order并排序query

private function parseOrder($order, $query)
    {
        $columns = explode(',', $order);
        foreach ($columns as $column) {
            if ($column[0] === '-') {
                $column = substr($column,1);
                $query->orderByDesc($column);
            } else {
                $query->orderBy($column);
            }
        }
    }

函数与order类型int一起正常工作,但是当我尝试使用订单类型string时,函数不会返回数据。

数据示例:

"id": 1,
        "title": "Corporis maxime vero aperiam labore ipsum laborum repudiandae.",
        "text": "Possimus enim modi nihil saepe atque cum. Est consequuntur ut commodi non dolores sint adipisci. Non voluptas consequatur nam ratione velit et deleniti. Corrupti rerum delectus voluptatem fugit.",
        "image_id": 24,
        "author_id": 24,
        "source_id": 1,
        "type_id": 1,
        "editor_text": "Esse labore odit voluptatum ea doloremque praesentium. Asperiores id voluptatem et voluptatem. Sequi sint expedita eum nam non pariatur ea. Deleniti ut magni nihil eveniet.",
        "recipe": "Recipe: Hatter. 'You might just as the other.' As soon as there seemed to be sure, she had never had fits, my dear, and that you couldn't cut off a head could be no chance of this, so that her neck from.",
        "recipe_link": "http://www.bradtke.net/",
        "count_recipe_link_redirect": 998,
        "recommended_at": "2017-08-16 12:28:21",
        "created_at": "2017-08-17 13:13:44",
        "updated_at": "2017-08-17 13:13:44",
        "deleted_at": null

0 个答案:

没有答案