# 排序和过滤

虽然在Laravel中有一个约定和一些内置工具用于分页，但是没有任何用于排序的，所以你必须自己解决这个问题。 我将在这里给出一个快速的代码示例，我将类似JSON API规范一样设置查询参数（在下面的侧边栏中描述）

> JSON API 规范
>
> JSON API 是一个标准，用于处理基于JSON的API中的许多最常见任务：过滤，排序，分页，身份验证，嵌入，链接，元数据等等。
>
> Laravel的默认分页并不完全符合JSON API规范，但它可以让您从正确的方向开始。 JSON API规范的其余部分大部分是你必须选择（或不选择）手动实现的。
>
> 例如这里有一个JSON API 规范，用于处理如何构造数据以及返回错误。
>
> 文档应该至少包含如下顶级成员之一
>
> * 数据：文档的“主要数据”
> * 错误：一个错误对象数组
> * 元：一个包含非标准元信息的元对象

> 成员数据以及错误MUST NOT 在相同的文档内
>
> 但是要注意：将JSON API作为规范是很好的，但它也需要相当多的基础来运行它。 我们不会在这些例子中完全使用它，但我将使用它的想法作为灵感。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://liseen315.gitbook.io/laravel/bian-xie-apis/pai-xu-he-guo-lv.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
