如何解决Laravel - Blade的逻辑问题

时间:2016-02-17 22:31:09

标签: php laravel blade laravel-blade php-carbon

我有$ win-> start,$ article-> from和$ article-> days

现在我想创建这样的HTML:

if ($article->from)  >  (Carbon::now()->addDays($article->days))  {
    $r = Carbon::now()->addDays($article->days)
    if ($r > $win->start) {
    <div>get VOUCHER</div>
        }
    else {
    <div>ACTIVE</div>
    }
    else {
    $r = $article->from
    if ($r > $win-> start) {
    <div>get VOUCHER</div>
        }
    else {
    <div>ACTIVE</div>
    }
}

请帮助我用正确的刀片解决这个逻辑问题 - 碳代码...如何在刀片中创建两个?

1 个答案:

答案 0 :(得分:1)

我认为这应该可以解决问题:

 @foreach($wins as $win)
     <div class="row">
         <div class="col-md-4">
             <p>{{ date('d M Y', strtotime($win->start)) }}</p>
         </div>
         <div class="col-md-4 text-right">
             <p><strong>{{$win->price}} </strong>euros</p>
         </div>
     @if($article->from > \Carbon\Carbon::now()->addDays($article->days))
         {{ $r = \Carbon\Carbon::now()->addDays($article->days) }}
         @if($r > $win->start) 
             <div>get VOUCHER</div>
         @else
            <div>ACTIVE</div>
         @endif
     @else
        {{ $r = $article->from }}
        @if($r > $win-> start)
            <div>get VOUCHER</div>
        @else
            <div>ACTIVE</div>
        @endif
    @endif
 </div>
 <hr style="margin:0px;">
@endforeach

更新:使用完整代码段

更多信息:https://laravel.com/docs/5.1/blade#control-structures