【发布时间】:2013-06-20 18:31:34
【问题描述】:
试图防止用户过快发布 cmets,因此计划使用 15 秒的间隔。
此查询无法查看是否在过去 15 秒内发表了评论。我做错了什么?
表:
id | comment | created_at |
==============================================
2 | blah casd | 2013-06-20 18:14:17 |
但是,我无法让它与 Eloquent 一起使用
//are they commenting too fast?
$protection = DB::table('comments')
->where('user_id', '=', $userid)
->where('created_at', '<', '(NOW(), INTERVAL 15 SECOND)')
->get();
if(!empty($protection)) {
return Redirect::back()->with_message('Please wait 15 seconds between comments.', 'error');
}
【问题讨论】:
-
如果你使用的是 Laravel 4,那么我建议你使用 Carbon。只需将 Provider 以及
app/config/app.php中的别名添加到列表中。更多关于碳的信息:github.com/briannesbitt/Carbon -
不幸的是我正在使用 L3
标签: php mysql laravel eloquent