다소 얇은 docs을 확인했지만 아직 어떻게하는지 잘 모르겠습니다.페이징 기능을 만드는 방법은 무엇입니까?
나는 컬렉션이 있습니다. 페이 지 네이터를 수동으로 만들고 싶습니다.
나는 내 컨트롤러에서, 내가 좋아하는 뭔가를해야 생각 :
new \Illuminate\Pagination\LengthAwarePaginator()
하지만, 내가 원하는 내가 컬렉션을 슬라이스 필요합니까 무엇 PARAMS? 또한 내보기에 '링크'를 어떻게 표시합니까?
누군가가 간단한 예를 게시하여 페이지 분류기를 만드는 방법이 있습니까?
예를 들어, 나는 웅변을 매기기를 원하지 않습니다. 사용자 :: 페이지 매기기 (10);
public function __construct($items, $total, $perPage, $currentPage = null, array $options = [])
{
foreach ($options as $key => $value) {
$this->{$key} = $value;
}
$this->total = $total;
$this->perPage = $perPage;
$this->lastPage = (int) ceil($total/$perPage);
$this->path = $this->path != '/' ? rtrim($this->path, '/') : $this->path;
$this->currentPage = $this->setCurrentPage($currentPage, $this->pageName);
$this->items = $items instanceof Collection ? $items : Collection::make($items);
}
보다 약 LengthAwarePaginator
표시를 참조하십시오 LengthAwarePaginator (생성자)에 대한 소스 코드에 따르면
$page = request()->get('page'); // By default LengthAwarePaginator does this automatically.
$collection = collect(...array...);
$total = $collection->count();
$perPage = 10;
$paginatedCollection = new \Illuminate\Pagination\LengthAwarePaginator(
$collection,
$total,
$perPage,
$page
);
:
감사하지만이 질문에 완전히 대답하지 않습니다. - "컬렉션이 있습니다. 수동으로 페이징 기능을 만들고 싶습니다." 당신은 웅변 모델에 대해 오프셋 등을 사용하고 있습니다. – panthro
아, 그렇다면 컬렉션에 모든 요소가 포함되어 있습니까? 아니면 자체적으로 페이지가 매겨진 목록입니까? – Jonathon
@panthro 업데이트 된 답변보기 – Jonathon