如果 blade 模板中的更新时间少于 8 小时,则显示消息
Show message if update time is less tha 8 hours in blade template
也许很简单,但我有一个提交表单,我想对其进行限制,这样用户应该能够每 8 小时更新一次。
我在数据库 table 中有 updated_at
列,它在 timestamp
中存储上次更新时间:2016-10-21 09:56:13
现在在我的 blade 模板中,我尝试这样检查
@if($time->updated_at < 8 hour)
// show message to come back after 8 hours
@else
// show the form
@endif
我有
'syntax error, unexpected 'hour' (T_STRING)'
我知道我为什么会得到这个,但我不知道如何做...我需要转换当前时间然后如何显示 8 小时吗?喜欢 60*60*8
?
如果您使用的是 laravel 时间戳,那么 updated_at 始终是 carbon 的对象,因此您可以使用 carbon 来区分当前 date/time 和您的模型 updated_at
@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
也许很简单,但我有一个提交表单,我想对其进行限制,这样用户应该能够每 8 小时更新一次。
我在数据库 table 中有 updated_at
列,它在 timestamp
中存储上次更新时间:2016-10-21 09:56:13
现在在我的 blade 模板中,我尝试这样检查
@if($time->updated_at < 8 hour)
// show message to come back after 8 hours
@else
// show the form
@endif
我有
'syntax error, unexpected 'hour' (T_STRING)'
我知道我为什么会得到这个,但我不知道如何做...我需要转换当前时间然后如何显示 8 小时吗?喜欢 60*60*8
?
如果您使用的是 laravel 时间戳,那么 updated_at 始终是 carbon 的对象,因此您可以使用 carbon 来区分当前 date/time 和您的模型 updated_at
@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