Support the ongoing development of Laravel.io →
Eloquent Blade

I don't know what to say in the if statement.


                @foreach($posts as $post)
		   @if($post->created_at->isYesterday())
                        Yesterday {{-- $post->created_at->isWeekday() --}}
                    @elseif($post->created_at->isToday())
                        Today  {{-- $post->created_at->isWeekday() --}}
                    @elseif(strtotime($post->created_at) > strtotime('-365 days'))
                        {{ $post->created_at->format('l') }} {{ $post->created_at->format('F d') }}th 
                    @endif
		@endforeach

I want to make a Headline between my posts like:

Today

  • Post 1,
  • Post 2 ....

Yesterday

  • Post 1,
  • Post 2 ....
Last updated 2 years ago.
0
Solution

Make three collections by filtering your posts collection

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

HenLab henlab Joined 8 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.