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

[Question] @forelse and other missing #49

Closed
Anahkiasen opened this issue Jan 15, 2013 · 11 comments
Closed

[Question] @forelse and other missing #49

Anahkiasen opened this issue Jan 15, 2013 · 11 comments

Comments

@Anahkiasen
Copy link
Contributor

A lot of Blade was trimmed down in the making of Laravel 4, and while some I can do without, I found the @forelse loop really useful and clean, is there any plan to bring it back ?

@jasonlewis
Copy link
Contributor

Not sure.

But I'd 👍 to see it brought back for sure.

@taylorotwell
Copy link
Member

There was a slight bug in @forelse actually and I just wanted to address it. I do plan to try to bring it back in.

@Zizaco
Copy link

Zizaco commented Feb 1, 2013

👍

1 similar comment
@stsaranchin
Copy link

👍

@stormpat
Copy link

Before is comes to L4 you could just do:

@if (count($artist->albums) > 0)
@foreach ($artist->albums as $artistalbum)
{{ $artistalbum->albumTitle }}
@else
This artist has no albums
@endif

@Anahkiasen
Copy link
Contributor Author

Well that's what I do of course but that adds a lot of clutter.

@taylorotwell
Copy link
Member

@forelse is pretty tricky to actually implement properly. going to deprecate it.

@casoetan
Copy link

casoetan commented Apr 4, 2013

Been battling with the forelse loop for upwards of an hour till I saw this. Thanks @gkunno

@if (count($artist->albums) > 0)
  @foreach ($artist->albums as $artistalbum)
    {{ $artistalbum->albumTitle }}
  @endforeach
@else
  This artist has no albums
@endif

@ibrasho
Copy link
Contributor

ibrasho commented Jun 1, 2013

@taylorotwell, want kind of trickiness is involved?
We can come up with a decent solution.

@ghost
Copy link

ghost commented Sep 30, 2013

SMARTY (optional else):

{foreach $myArray as $item}
    <li>{$item}</li>
{foreachelse}
    <li>Nothing to show</li>
{/foreach}

HANDLEBARS (optional else):

{{#each myArray}}
    <li>{{this}}</li>
{{else}}
    <li>Nothing to show</li>
{{/each}}

why not BLADE?

@foreach($myArray as $item)
    <li>{{$item}}</li>
@else
    <li>Nothing to show</li>
@endforeach

@robclancy
Copy link
Contributor

Because it is deprecated, that's why. I'm sure you can handle it.

joelharkes pushed a commit to joelharkes/framework_old that referenced this issue Mar 7, 2019
dbpolito pushed a commit to dbpolito/framework that referenced this issue Oct 1, 2019
gonzalom pushed a commit to Hydrane/tmp-laravel-framework that referenced this issue Oct 12, 2023
Fix Total Downloads badge in readme
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

9 participants