vandyczech's avatar

Pagination array

I have this array and I want make a pagination this. This array has 14 items.

LengthAwarePaginator {#574 ▼
#total: 14
#lastPage: 3
#items: Collection {#575 ▼
    #items: array:14 [▼
    0 => array:2 [▼
    "name" => "photo"
    "url" => "/photo"
  ]
  1 => array:2 [▶]
  2 => array:2 [▶]
  3 => array:2 [▶]
  4 => array:2 [▶]
  5 => array:2 [▶]
  6 => array:2 [▶]
  7 => array:2 [▶]
  8 => array:2 [▶]
  9 => array:2 [▶]
  10 => array:2 [▶]
  11 => array:2 [▶]
  12 => array:2 [▶]
  13 => array:2 [▶]
]
 }
    #perPage: 5
    #currentPage: 1
    #path: "settings#theme-pages"
    #query: []

In blade fike i have this:

 @foreach($themePages as $page)

                {{ $page['name'] }}

            @endforeach

            {{ $themePages->links()  }}

All works perfect but the items are still on current page only, not divide per pages ...

0 likes
6 replies
vandyczech's avatar
return view('admin.settings')

        ->with('themePages' , $this->themePagesWithPaginate());
ekhlas's avatar

Hi

if i understand good enough then you use

$per_page=5;
$page=$request->input('page');
$total_records=14;   your  Count Query result
$slice = array_slice([], $per_page * ($page - 1), $per_page);
$result = Pagination::makeLengthAware($slice,$total_records, $per_page);  

in

$this->themePagesWithPaginate()

for pagination.

rin4ik's avatar

show your variable themePages how you get that?

Please or to participate in this conversation.