@forelse ($things as $thing)
{{ $thing }}
@empty
There are no things
@endforelse
Laravel Blade not empty directive
I was reading the docs and I noticed that Laravel only has the @empty directive and it doesn't with the @else so I was wondering, how can I do the inverse and check if the collection is not empty, show the results and if it's empty show a message?
Right now I'm doing something like @if(! $plans->isEmpty()) but it's really ugly compared with the directives solution such as @empty.
Might not be attractive, but I don't see a good/better way around it for your criteria. If it was just a matter of looping over data if it existed and outputting a message if it didn't, that's simple. You have an extra requirement, which is to output a message (a form in this case) AND loop over the data if there is data to loop over, and output a message if there isn't. That's exactly what your succinct code does. I don't know how you'd improve it really, except make an @empty/@notEmpty directive, which would just replace
@if(! $plans->isEmpty())
with
@notEmpty($plans)
so not really saving much....
Please or to participate in this conversation.