laravel怎样使用UrlWindow?

看分页时看到的链接描述
博主说laravel底层提供的 要use一下 我直接use UrlWindow;了一下 并不行怎么回事?
$window = UrlWindow::make($posts);

public function fetch()
{
    // 每页显示6篇文章,如果页码太多,当前页码左右只显示2个页码
    $posts = Post::paginate(6)->onEachSide(2)->withPath(url('post'));
    // 处理页码及对应分页URL(页码过多,部分页码省略)
    $window = UrlWindow::make($posts);
    $pages = array_filter([
        $window['first'],
        is_array($window['slider']) ? '...' : null,
        $window['slider'],
        is_array($window['last']) ? '...' : null,
        $window['last'],
    ]);
    return response()->json([
        'paginator' => $posts,
        'elements' => $pages
    ]);
}
阅读 1.9k
1 个回答
use Illuminate\Pagination\UrlWindow;
推荐问题