Laravel carbon IF statement

- 1 answer

Ad

I try to create DOM with blade and carbon if auction is live by this way:

@if ( {{(Carbon\Carbon::now()) < ($article->auction_end)}} )
  <div class="col-md-3 leftEdge">
    <p>Auction is ACTIVE</p>
  </div>
@endif

but I get error:

FatalErrorException in e91f1d7e7c19547ed6cb12e22b4988e0 line 21: syntax error, unexpected '<'

Ad

Answer

Ad

You should use:

@if (Carbon\Carbon::now() < $article->auction_end)
<div class="col-md-3 leftEdge">
<p>Auction is ACTIVE</p>
</div>
@endif

You should not use {{ in control statements

In addition to compare dates in valid way, you should also change comparison using Carbon lte operator, so finnaly it should look like this:

@if (Carbon\Carbon::now()->lte(Carbon\Carbon::parse($article->auction_end)))
<div class="col-md-3 leftEdge">
<p>Auction is ACTIVE</p>
</div>
@endif
Ad
source: stackoverflow.com
Ad