Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$loop->index and $loop->iteration not working correctly #96

Closed
ed-iv opened this issue Aug 28, 2019 · 3 comments
Closed

$loop->index and $loop->iteration not working correctly #96

ed-iv opened this issue Aug 28, 2019 · 3 comments

Comments

@ed-iv
Copy link

ed-iv commented Aug 28, 2019

Hey there,

Was working with loop variables today, and am getting some issues involving $loop->index and $loop->iteration.

  1. $loop->index is returning the 1-based index of current loop item (i.e. it is doing what $loop->iteration should be doing)

  2. $loop->iteration does not appear to be implemented (just comes back as NULL)

Will take a look at source as time permits. Thanks for the package!

@jorgecc
Copy link
Member

jorgecc commented Aug 30, 2019

What do you want to do?.

Do you want to read the index from @for or @foreach ?

@ed-iv
Copy link
Author

ed-iv commented Sep 1, 2019

Yea, I think Laravel only makes this available within @foreach (not 100% on that though). As documented here, the $loop variable gives access to certain properties within the context of a particular loop.

The list of properties has grown a bit larger in recent versions of Laravel to include a few that don't appear to be included in your implementation. As far as I can tell, these loop variables are initialized within each loop by your compileForEach method with a call to addLoop. The newer loop variables that I don't see in addLoop are: iteration, even, and odd.

Also $loop->index appears to be starting at 1 instead of 0. I see it being initialized to 0 in addLoop though so it must be incremented prior to the first loop somehow?

jorgecc added a commit that referenced this issue Dec 21, 2019
    * For #96 added $loop->even and $loop->odd and $loop->iteration
    * Also, **$loop->index now starts with 0 instead of 1**
@jorgecc
Copy link
Member

jorgecc commented Dec 21, 2019

Done in #3.32

@jorgecc jorgecc closed this as completed Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants