2016-04-17 3 views
0

はので、私は記事のモデルで書く私のアプリでは、物品のためのオークションは生きているんLaravel 5.1私がチェックする必要がある。ここ比較カーボン日付

@if ($article->Closeauction()) 
          <td> 
          auction is live 
         </td> 
          @else 
          <td> 
          auction is closed 
          </td> 
         @endif 

が、私も試してください : enter image description here

がUPDATE:01私は、私はエラーを得たbecouse問題を抱えていますCarbon::parse('to'):私はあなたの問題がここにあると思い

ErrorException in Carbon.php line 425: Unexpected data found. Unexpected data found. Unexpected data found. Trailing data (View: C:\wamp\www\project\resources\views\articles\index.blade.php)

+0

私も試してみてください。パブリック関数scopeCloseauction($クエリを){ $ query-> where(( 'to')。subDays( 'auction_end')、 '>'、Carbon :: now()); }しかし、言う:未定義関数を呼び出すApp \ subDays() – Andrew

答えて

1

あなたは何か、あなたのArticleモデルに、このような機能を追加することが可能です。

public function isLive() 
{ 
    $first = Carbon::parse($this->to)->subDays($this->auction_end); 
    $second = Carbon::now(); 
    return $first->lte($second); 
} 

、今、あなたのビューで使用できます。

@if ($article->isLive()) 
    <td> 
     live 
    </td> 
    @else 
    <td> 
     closed 
    </td> 
@endif 
0

public function isLive($to,$auction_end) { 
    $first = Carbon::create($to).subDays($auction_end); 
    $second = Carbon::now(); 
     return ($first->lte($second)); 
    } 

とビューで:

@if ($article->isLive($article->to,$article->auction_end)) 
          <td> 
          live 
         </td> 
          @else 
          <td> 
           closed 
          </td> 
         @endif 

が、今私は、このエラーを与えるモデルの機能を追加するためで。ここで何をしたいですか? Carbon :: parseメソッドは、文字列の日付をCarbonの日付に変換しようとします。 See the doc。私はCarbonが文字列 'to'を解析できるとは思わない。日付間の差異を確認する場合はをdiffInDaysのような適切な方法にします。

関連する問題