这可能很简单,但我有一个提交表单,我想限制它,所以用户应该能够每8小时更新一次。
我在数据库表中有updated_at
列,它将上次更新时间存储在timestamp
:2016-10-21 09:56:13
中
现在在我的刀片模板中,我试着像这样检查
@if($time->updated_at < 8 hour)
// show message to come back after 8 hours
@else
// show the form
@endif
我有
'语法错误,意外的'hour'(T_STRING('
我知道我为什么得到这个,但我不知道如何制作if…我需要转换当前时间,然后如何呈现8小时吗?像60*60*8
?
如果您使用比updated_at更大的时间戳,则它始终是carbon的对象,因此您可以使用carbon来获得当前日期/时间与更新的模型之间的差异
@if(Carbon'Carbon::now()->diffInHours($time->updated_at) > 8)
//time difference is greater than 8
@else
// time difference is less than or equal to 8 hours
@endif
假设您的updated_at
使用Laravel的默认时间戳
@if((time() - strtotime($time->updated_at)) < 28800)
// show message to come back after 8 hours
@else
// show the form
@endif