ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
<article><h1>Laravel 的分页功能</h1><ul><li><a href="#introduction">简介</a></li><li><a href="#basic-usage">基本使用</a><ul><li><a href="#paginating-query-builder-results">对查询语句构造器进行分页</a></li><li><a href="#paginating-eloquent-results">对 Eloquent 模型进行分页</a></li><li><a href="#manually-creating-a-paginator">手动创建分页</a></li></ul></li><li><a href="#displaying-pagination-results">显示分页结果</a><ul><li><a href="#converting-results-to-json">将结果转换为 JSON</a></li></ul></li><li><a href="#customizing-the-pagination-view">自定义分页视图</a></li><li><a href="#paginator-instance-methods">分页器实例方法</a></li></ul><p><a name="introduction"></a></p><h2><a href="#introduction">简介</a></h2><p>在其他的框架中,分页是令人非常烦恼的。 Laravel 的分页器为 <a href="/docs/5.4/queries">查询构造器</a> 和 <a href="/docs/5.4/eloquent">Eloquent ORM</a> 集成提供了方便,并提供基于数据库结果集的分页开箱即用。分页器生产的 HTML 兼容 <a href="https://getbootstrap.com/">Bootstrap CSS framework</a>.</p><p><a name="basic-usage"></a></p><h2><a href="#basic-usage">基本使用</a></h2><p><a name="paginating-query-builder-results"></a></p><h3>对查询语句构造器进行分页</h3><p>有几种方法可以对项目进行分页。最简单的是在 <a href="/docs/5.4/queries">查询语句构造器</a> 或 <a href="/docs/5.4/eloquent">Eloquent 查询</a> 中使用 <code class=" language-php">paginate</code> 方法。 <code class=" language-php">paginate</code> 方法会自动基于当前用户查看的当前页面来设置适当的限制和偏移。默认情况下,当前页面通过 HTTP 请求所带的 <code class=" language-php"><span class="token operator">?</span>page</code> 参数的值来检测。当然,这个值会被 Laravel 自动检测,并且自动插入到由分页器生产的链接中。</p><p>首先,让我们先来看看如何在查询上调用 <code class=" language-php">paginate</code> 方法。在这个例子中,传递给 <code class=" language-php">paginate</code> 方法的唯一参数是你希望在「每页」显示的数据数。在这种情况下,让我们指定希望每页显示 <code class=" language-php"><span class="token number">15</span></code> 条数据:</p><pre class=" language-php"><code class=" language-php"><span class="token delimiter">&lt;?php</span> <span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Controllers</span><span class="token punctuation">;</span> <span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>DB</span><span class="token punctuation">;</span> <span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Controllers<span class="token punctuation">\</span>Controller</span><span class="token punctuation">;</span> <span class="token keyword">class</span> <span class="token class-name">UserController</span> <span class="token keyword">extends</span> <span class="token class-name">Controller</span> <span class="token punctuation">{</span> <span class="token comment" spellcheck="true">/** * 显示应用中所有的用户 * * @return Response */</span> <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function">index<span class="token punctuation">(</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token variable">$users</span> <span class="token operator">=</span> <span class="token scope">DB<span class="token punctuation">::</span></span><span class="token function">table<span class="token punctuation">(</span></span><span class="token string">'users'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">paginate<span class="token punctuation">(</span></span><span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">return</span> <span class="token function">view<span class="token punctuation">(</span></span><span class="token string">'user.index'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">'users'</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token variable">$users</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span></code></pre><blockquote class="has-icon note"><p><div class="flag"><span class="svg"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" version="1.1" x="0px" y="0px" width="90px" height="90px" viewBox="0 0 90 90" enable-background="new 0 0 90 90" xml:space="preserve"><path fill="#FFFFFF" d="M45 0C20.1 0 0 20.1 0 45s20.1 45 45 45 45-20.1 45-45S69.9 0 45 0zM45 74.5c-3.6 0-6.5-2.9-6.5-6.5s2.9-6.5 6.5-6.5 6.5 2.9 6.5 6.5S48.6 74.5 45 74.5zM52.1 23.9l-2.5 29.6c0 2.5-2.1 4.6-4.6 4.6 -2.5 0-4.6-2.1-4.6-4.6l-2.5-29.6c-0.1-0.4-0.1-0.7-0.1-1.1 0-4 3.2-7.2 7.2-7.2 4 0 7.2 3.2 7.2 7.2C52.2 23.1 52.2 23.5 52.1 23.9z"></path></svg></span></div> 目前,使用 <code class=" language-php">groupBy</code> 语句的分页操作无法由 Laravel 有效执行。如果你需要在一个分页结果集中使用 <code class=" language-php">groupBy</code>,建议你查询数据库并手动创建分页器。</p></blockquote><h4>「简单分页」</h4><p>如果你只需要在你的分页视图中显示简单的「上一页」和「下一页」的链接,你可以使用 <code class=" language-php">simplePaginate</code> 方法来执行更高效的查询。当你在渲染视图时不需要显示页码链接,这对于大数据集非常有用。</p><pre class=" language-php"><code class=" language-php"><span class="token variable">$users</span> <span class="token operator">=</span> <span class="token scope">DB<span class="token punctuation">::</span></span><span class="token function">table<span class="token punctuation">(</span></span><span class="token string">'users'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">simplePaginate<span class="token punctuation">(</span></span><span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre><p><a name="paginating-eloquent-results"></a></p><h3>对 Eloquent 模型进行分页</h3><p>你也可以对 <a href="/docs/5.4/eloquent">Eloquent</a> 查询进行分页。在这个例子中,我们将对 <code class=" language-php">User</code> 模型进行分页并且每页显示 <code class=" language-php"><span class="token number">15</span></code> 条数据。正如你看到的,语法几乎与基于查询语句构造器的分页相同:</p><pre class=" language-php"><code class=" language-php"><span class="token variable">$users</span> <span class="token operator">=</span> <span class="token scope">App<span class="token punctuation">\</span>User<span class="token punctuation">::</span></span><span class="token function">paginate<span class="token punctuation">(</span></span><span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre><p>当然,你可以在对查询设置了其他限制之后调用 <code class=" language-php">paginate</code> 方法,例如 <code class=" language-php">where</code> 子句:</p><pre class=" language-php"><code class=" language-php"><span class="token variable">$users</span> <span class="token operator">=</span> <span class="token scope">User<span class="token punctuation">::</span></span><span class="token function">where<span class="token punctuation">(</span></span><span class="token string">'votes'</span><span class="token punctuation">,</span> <span class="token string">'&gt;'</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">paginate<span class="token punctuation">(</span></span><span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre><p>你也可以在 Eloquent 模型进行分页使用 <code class=" language-php">simplePaginate</code> 方法:</p><pre class=" language-php"><code class=" language-php"><span class="token variable">$users</span> <span class="token operator">=</span> <span class="token scope">User<span class="token punctuation">::</span></span><span class="token function">where<span class="token punctuation">(</span></span><span class="token string">'votes'</span><span class="token punctuation">,</span> <span class="token string">'&gt;'</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">simplePaginate<span class="token punctuation">(</span></span><span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre><p><a name="manually-creating-a-paginator"></a></p><h3>手动创建分页</h3><p>有时候你可能希望手动创建一个分页实例,并传递其到项目数组中。你可以依据你的需求创建 <code class=" language-php">Illuminate\<span class="token package">Pagination<span class="token punctuation">\</span>Paginator</span></code> 或 <code class=" language-php">Illuminate\<span class="token package">Pagination<span class="token punctuation">\</span>LengthAwarePaginator</span></code> 实例。</p><p><code class=" language-php">Paginator</code> 类不需要知道结果集中的数据项总数;然而,由于这个,该类没有用于检索最后一页索引的方法。<code class=" language-php">LengthAwarePaginator</code> 接收的参数几乎和 <code class=" language-php">Paginator</code> 一样;但是,它需要计算结果集中的数据项总数。</p><p>换一种说法,<code class=" language-php">Paginator</code> 对应于查询语句构造器和 Eloquent 的 <code class=" language-php">simplePaginate</code> 方法,而 <code class=" language-php">LengthAwarePaginator</code> 对应于 <code class=" language-php">paginate</code> 方法。</p><blockquote class="has-icon note"><p><div class="flag"><span class="svg"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" version="1.1" x="0px" y="0px" width="90px" height="90px" viewBox="0 0 90 90" enable-background="new 0 0 90 90" xml:space="preserve"><path fill="#FFFFFF" d="M45 0C20.1 0 0 20.1 0 45s20.1 45 45 45 45-20.1 45-45S69.9 0 45 0zM45 74.5c-3.6 0-6.5-2.9-6.5-6.5s2.9-6.5 6.5-6.5 6.5 2.9 6.5 6.5S48.6 74.5 45 74.5zM52.1 23.9l-2.5 29.6c0 2.5-2.1 4.6-4.6 4.6 -2.5 0-4.6-2.1-4.6-4.6l-2.5-29.6c-0.1-0.4-0.1-0.7-0.1-1.1 0-4 3.2-7.2 7.2-7.2 4 0 7.2 3.2 7.2 7.2C52.2 23.1 52.2 23.5 52.1 23.9z"></path></svg></span></div> 当手动创建分页器实例时,你应该手动「切割」传递给分页器的结果集。如果你不确定如何去做到这一点,查阅 PHP 的函数 <a href="https://secure.php.net/manual/en/function.array-slice.php">array_slice</a> 。</p></blockquote><p><a name="displaying-pagination-results"></a></p><h2><a href="#displaying-pagination-results">显示分页结果</a></h2><p>当调用 <code class=" language-php">paginate</code> 方法的时候,你将会接收到一个 <code class=" language-php">Illuminate\<span class="token package">Pagination<span class="token punctuation">\</span>LengthAwarePaginator</span></code> 实例。而当你调用 <code class=" language-php">simplePaginate</code> 方法时,你将会接收到一个 <code class=" language-php">Illuminate\<span class="token package">Pagination<span class="token punctuation">\</span>Paginator</span></code> 实例。这些对象提供了一些描述结果集的方法。除了这些辅助方法,分页器是迭代器并且可以作为数组循环。因此,一旦检索到结果集,你可以使用 <a href="/docs/5.4/blade">Blade</a> 模板显示结果集并渲染页面链接:</p><pre class=" language-php"><code class=" language-php"><span class="token markup"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>container<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span></span> @<span class="token keyword">foreach</span> <span class="token punctuation">(</span><span class="token variable">$users</span> <span class="token keyword">as</span> <span class="token variable">$user</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">{</span> <span class="token variable">$user</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token property">name</span> <span class="token punctuation">}</span><span class="token punctuation">}</span> @<span class="token keyword">endforeach</span> <span class="token markup"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span></span> <span class="token punctuation">{</span><span class="token punctuation">{</span> <span class="token variable">$users</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">links<span class="token punctuation">(</span></span><span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></code></pre><p><code class=" language-php">links</code> 方法将会渲染结果集中的其他页链接。这些链接中每一个都已经包含了 <code class=" language-php"><span class="token operator">?</span>page</code> 查询字符串变量。记住,<code class=" language-php">links</code> 方法生产的 HTML 兼容 <a href="https://getbootstrap.com">Bootstrap CSS framework</a></p><h4>自定义分页器的 URI</h4><p><code class=" language-php">withPath</code> 方法允许你在生成分页链接时自定义 URI 。例如,如果你想分页器生成的链接如 <code class=" language-php">http<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>example<span class="token punctuation">.</span>com<span class="token operator">/</span>custom<span class="token operator">/</span>url<span class="token operator">?</span>page<span class="token operator">=</span>N</code>,你应该传递 <code class=" language-php">custom<span class="token operator">/</span>url</code> 到 <code class=" language-php">withPath</code> 方法:</p><pre class=" language-php"><code class=" language-php"><span class="token scope">Route<span class="token punctuation">::</span></span><span class="token function">get<span class="token punctuation">(</span></span><span class="token string">'users'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token variable">$users</span> <span class="token operator">=</span> <span class="token scope">App<span class="token punctuation">\</span>User<span class="token punctuation">::</span></span><span class="token function">paginate<span class="token punctuation">(</span></span><span class="token number">15</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token variable">$users</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">withPath<span class="token punctuation">(</span></span><span class="token string">'custom/url'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true"> // </span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre><h4>附加参数到分页链接中</h4><p>你可以使用 <code class=" language-php">append</code> 方法附加查询参数到分页链接中。例如,要附加 <code class=" language-php">sort<span class="token operator">=</span>votes</code> 到每个分页链接,你应该这样调用 <code class=" language-php">append</code> 方法:</p><pre class=" language-php"><code class=" language-php"><span class="token punctuation">{</span><span class="token punctuation">{</span> <span class="token variable">$users</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">appends<span class="token punctuation">(</span></span><span class="token punctuation">[</span><span class="token string">'sort'</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token string">'votes'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">links<span class="token punctuation">(</span></span><span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></code></pre><p>如果你希望附加「哈希片段」到分页器的链接中,你应该使用 <code class=" language-php">fragment</code> 方法。例如,要附加 <code class=" language-php"><span class="token comment" spellcheck="true">#foo</span></code> 到每个分页链接的末尾,应该这样调用 <code class=" language-php">fragment</code> 方法:</p><pre class=" language-php"><code class=" language-php"><span class="token punctuation">{</span><span class="token punctuation">{</span> <span class="token variable">$users</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">fragment<span class="token punctuation">(</span></span><span class="token string">'foo'</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">links<span class="token punctuation">(</span></span><span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></code></pre><p><a name="converting-results-to-json"></a></p><h3>将结果转换为 JSON</h3><p>Laravel 分页器结果类实现了 <code class=" language-php">Illuminate\<span class="token package">Contracts<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Jsonable</span></code> 接口契约并且提供 <code class=" language-php">toJson</code> 方法,所以它很容易将你的分页结果集转换为 Json。你也可以简单地通过从路由或者控制器动作返回分页实例并将其转换为 JSON :</p><pre class=" language-php"><code class=" language-php"><span class="token scope">Route<span class="token punctuation">::</span></span><span class="token function">get<span class="token punctuation">(</span></span><span class="token string">'users'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token scope">App<span class="token punctuation">\</span>User<span class="token punctuation">::</span></span><span class="token function">paginate<span class="token punctuation">(</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre><p>从分页器获取的 JSON 将包含元信息,如: <code class=" language-php">total</code>, <code class=" language-php">current_page</code>, <code class=" language-php">last_page</code> 等等。实际的结果对象将通过 JSON 数组中的 <code class=" language-php">data</code> 键来获取。 以下是一个从路由返回分页器实例创建的 JSON 示例:</p><pre class=" language-php"><code class=" language-php"><span class="token punctuation">{</span> <span class="token string">"total"</span><span class="token punctuation">:</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token string">"per_page"</span><span class="token punctuation">:</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token string">"current_page"</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"last_page"</span><span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token string">"next_page_url"</span><span class="token punctuation">:</span> <span class="token string">"http://laravel.app?page=2"</span><span class="token punctuation">,</span> <span class="token string">"prev_page_url"</span><span class="token punctuation">:</span> <span class="token keyword">null</span><span class="token punctuation">,</span> <span class="token string">"from"</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">"to"</span><span class="token punctuation">:</span> <span class="token number">15</span><span class="token punctuation">,</span> <span class="token string">"data"</span><span class="token punctuation">:</span><span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token comment" spellcheck="true"> // Result Object </span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token comment" spellcheck="true"> // Result Object </span> <span class="token punctuation">}</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span></code></pre><p><a name="customizing-the-pagination-view"></a></p><h2><a href="#customizing-the-pagination-view">自定义分页视图</a></h2><p>在默认情况下,视图渲染显示的分页链接都兼容 Bootstrap CSS 框架。但是,如果你不使用 Bootstrap,你可以自定义你自己的视图去渲染这些链接。当在分页器实例中调用 <code class=" language-php">links</code> 方法,传递视图名称作为方法的第一参数:</p><pre class=" language-php"><code class=" language-php"><span class="token punctuation">{</span><span class="token punctuation">{</span> <span class="token variable">$paginator</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">links<span class="token punctuation">(</span></span><span class="token string">'view.name'</span><span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">}</span> <span class="token comment" spellcheck="true"> // 传递数据到视图中... </span><span class="token punctuation">{</span><span class="token punctuation">{</span> <span class="token variable">$paginator</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">links<span class="token punctuation">(</span></span><span class="token string">'view.name'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">'foo'</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token string">'bar'</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></code></pre><p>然而,自定义分页视图最简单的方法是通过 <code class=" language-php">vendor<span class="token punctuation">:</span>publish</code> 命令将它们导出到你的 <code class=" language-php">resources<span class="token operator">/</span>views<span class="token operator">/</span>vendor</code> 目录:</p><pre class=" language-php"><code class=" language-php">php artisan vendor<span class="token punctuation">:</span>publish <span class="token operator">--</span>tag<span class="token operator">=</span>laravel<span class="token operator">-</span>pagination</code></pre><p>这个命令将视图放置在 <code class=" language-php">resources<span class="token operator">/</span>views<span class="token operator">/</span>vendor<span class="token operator">/</span>pagination</code> 目录中。这个目录下的 <code class=" language-php"><span class="token keyword">default</span><span class="token punctuation">.</span>blade<span class="token punctuation">.</span>php</code> 文件对应于默认分页视图。你可以简单地编辑这个文件以修改分页的 HTML 。</p><p><a name="paginator-instance-methods"></a></p><h2><a href="#paginator-instance-methods">分页器实例方法</a></h2><p>每个分页器实例通过以下方法提供额外的分页信息:</p><ul><li><code class=" language-php"><span class="token variable">$results</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">count<span class="token punctuation">(</span></span><span class="token punctuation">)</span></code></li><li><code class=" language-php"><span class="token variable">$results</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">currentPage<span class="token punctuation">(</span></span><span class="token punctuation">)</span></code></li><li><code class=" language-php"><span class="token variable">$results</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">firstItem<span class="token punctuation">(</span></span><span class="token punctuation">)</span></code></li><li><code class=" language-php"><span class="token variable">$results</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">hasMorePages<span class="token punctuation">(</span></span><span class="token punctuation">)</span></code></li><li><code class=" language-php"><span class="token variable">$results</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">lastItem<span class="token punctuation">(</span></span><span class="token punctuation">)</span></code></li><li><code class=" language-php"><span class="token variable">$results</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">lastPage<span class="token punctuation">(</span></span><span class="token punctuation">)</span> <span class="token punctuation">(</span>当使用 simplePagination 时无效<span class="token punctuation">)</span></code></li><li><code class=" language-php"><span class="token variable">$results</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">nextPageUrl<span class="token punctuation">(</span></span><span class="token punctuation">)</span></code></li><li><code class=" language-php"><span class="token variable">$results</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">perPage<span class="token punctuation">(</span></span><span class="token punctuation">)</span></code></li><li><code class=" language-php"><span class="token variable">$results</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">previousPageUrl<span class="token punctuation">(</span></span><span class="token punctuation">)</span></code></li><li><code class=" language-php"><span class="token variable">$results</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">total<span class="token punctuation">(</span></span><span class="token punctuation">)</span> <span class="token punctuation">(</span>当使用 simplePagination 时无效<span class="token punctuation">)</span></code></li><li><code class=" language-php"><span class="token variable">$results</span><span class="token operator">-</span><span class="token operator">&gt;</span><span class="token function">url<span class="token punctuation">(</span></span><span class="token variable">$page</span><span class="token punctuation">)</span></code></li></ul><h2>译者署名</h2><table><thead><tr><th>用户名</th><th>头像</th><th>职能</th><th>签名</th></tr></thead><tbody><tr><td><a href="https://laravel-china.org/users/3848">@cjjian</a></td><td><img class="avatar-66 rm-style" src="https://dn-phphub.qbox.me/uploads/avatars/3848_1477641871.png?imageView2/1/w/100/h/100"></td><td>翻译</td><td>Nothing is impossible. <a href="https://github.com/jcc/">@Jiajian Chan</a> at Github</td></tr></tbody></table></article>