-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Blade @forelse #5028
Blade @forelse #5028
Conversation
👍 |
That was fast :) |
L3 feature back! 👍 How to use this? |
|
Now that I look at it (old documentation), I kind of prefer L3's syntax :p @forelse ($posts as $post)
{{ $post->body }}
@empty
There are not posts in the array!
@endforelse |
:( Hard to choose. I think |
Um, let's not forget empty() is a PHP method. So having |
How would this work when nested? Wouldn't the Kinda fragile if you ask me. |
Thoughts Joost?
|
Maybe something like this? protected $foreachDepth = 0;
protected function compileForeach($expression)
{
$empty = '$__empty_' . ++$this->foreachDepth;
return "<?php $empty = true; foreach{$expression}: $empty = false; ?>";
}
protected function compileForelse($expression)
{
$empty = '$__empty_' . $this->foreachDepth--;
return "<?php endforeach; if ($empty): ?>";
} I haven't thought it through completely, but I think we could probably make it work... |
I never thought about that, good point. Your count based solution would not work since a foreach does not necessarily also go with the forelse, hence the counters will go out of sync. The only solution I can think of would be to use the exact L3 syntax with a different foreach keyword, so we can be sure about the counter being in sync, in which case it would work fine. |
Actually, decrementing the counter also in I locally have a fix with a switch to L3's syntax, and while creating that one I thought about the aforementioned possibility to retain the syntax as it is now. Please let me know which we want to choose here, I believe there has not yet been another 4.2 tag so we may still switch I suppose. |
We can still switch if it's easier. No tag yet.
|
In the end, do not forget to update docs. |
No it's not? The docs are already uptodate. |
There is currently no |
@JoostK But it's right here! |
Allrighty, I was looking at the 4.1 docs. Apparently the version you see depends on the session (i.e. last used) instead of the url. |
Yes the url doesn't change when you switched version. Bugs me every fucking time. |
Thanks guys! I patched my 4.2 version with this pull request as #5046 will not make it, isn't it? |
@heinrichmartin What??? |
Sorry for the confusion. I seemingly made 2 mistakes here:
|
I still don't understand what you mean? |
I am a user of the latest L4 release. I saw Then I wondered how to tell about the wrong doc and chose this discussion. Finally, I wanted to tell that I am happy with your activity on this project in general and this issue - and I then was surprised by your post "What???". It looked a lot like I made something wrong or stupid ... I actually do not know even now, but I wanted to let you know, that nothing bad happened to the repository. Please let me know whether this cleared things a bit ... |
The current 4.2 release, and the one before it supports the new blade syntax completely, and the documentation was updated almost immediately. This really needs to go no further, and should not be discussed here on github. |
Implements #5009.
The update to a generic
foreach
statement may be changed, but that would need an additional keyword for this specific use-case.I may redo this against master if requested.