試圖防止用戶過快發佈評論,因此使用15秒間隔是計劃。Laravel/Eloquent - 15秒時間戳間隔
此查詢無法查看是否在最近15秒內發表了評論。我究竟做錯了什麼?
表:
id | comment | created_at |
==============================================
2 | blah casd | 2013-06-20 18:14:17 |
不過,我不能完全得到它與雄辯
//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'中的別名即可。更多關於碳在這裏:https://github.com/briannesbitt/Carbon –
不幸的是我正在與L3 – cantaffordretail