如何将剩余时间延长至消费日期..
{{$item->created_at->toDateString()->diffInDays($item->expired)}}
{{$item->created_at->toDateString() - $item->expired}}
答案 0 :(得分:2)
您正在尝试在字符串上调用函数。
请参阅:
$item
\ Illuminate \ Database \ Eloquent \ Model
$item->created_at
\ Carbon \ Carbon
$item->created_at->toDateString()
string
$item->created_at->toDateString()->diffInDays()
FatalThrowableError调用
到字符串
尝试:
{{ $item->created_at->diffInDays($item->expired) }}
评论后: 您的过期属性是字符串而不是日期: 告诉Eloquent将其变为日期:
class Item {
protected $dates = ['expired'];
}
答案 1 :(得分:2)
{{ $item->created_at->diffInDays($item->expired) }}