harunB10
harunB10

Reputation: 5197

Carbon date check if it is specified date

I have a link in my menu where I pass date to filter. But I want to achieve this:

For now I did this:

<li class="navMenu">
  <a href="/latest?date=
    @if (Carbon\Carbon::today()->isWeekday())

     {{Carbon\Carbon::yesterday()->format('Y-m-d')}}

    @else 
      {{Carbon\Carbon::now()->startOfWeek()->format('Y-m-d')}}
    @endif">{{ trans('language.newCampaigns') }}
   </a>
</li>

Upvotes: 2

Views: 1692

Answers (1)

apokryfos
apokryfos

Reputation: 40653

You can fall back to native PHP ->modify modifiers since Carbon inherits from date:

<li class="navMenu">
  <a href="/latest?date={{Carbon\Carbon::today()->modify("last weekday")->format('Y-m-d')}}">    
   </a>
</li>

Upvotes: 2

Related Questions