I want to check if my foreach is empty so the basic html markup isn\'t displayed with no results inside. I\'m trying to wrap it in an if statement and then if it is empty do not
This is my best solution if I understood the question well:
Use of $object->first()
method to run the code inside if
statement once, that is when on the first loop. The same concept is true with $object->last()
.
@if($object->first())
Email
@endif
@foreach ($object as $data)
{{ $data->email }}
@endforeach
@if($object->last())
@endif