How to add indexing on loop (Blade) with pagination
Hello, I have a list of objects that I have selected with the pagination function. I want to add an index number on the table during the loop. So on the first page to be like 1-10 (if the pagination is 10), on the second page (11-21) and so one for the other pages. If i use foreach with key and value the key always starts from 0 on any page. Does anyone know how i can add indexing on the pagination?
You should be able to access the first/last item value on the paginator instance.. Though this seems to be undocumented, by looking at the code firstItem() and lastItem()should be available.
For this example, lets say you are paginating a list of users..
Hello @willvincent, thanks for your reply. basically this is what I'm trying to achive
#
Name
Email
Role
Status
Registered
Action
@forelse($users as $user)
1
{{{ $user->name }}}
{{{ $user->email }}}
Admin
Active
{{{ date("d-m-Y", strtotime($user->created_at)) }}}
Edit@empty
No users have been found.
@endforelse
#
Name
Email
Role
Status
Registered
Action
{!! $users->render() !!}
the 1 to be auto increment based on the page that you are viewing
@firemaps yes, of course.. because $index is the row number in that result set.. based on a offset & limit query. And was kind of the entire point of the post -- how to show which users were being shown on a given page of a paginated list. ;)