Laravel carbon IF statement
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
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad