laravel 通过IP限制用户当天提交次数

//获取IP地址
$ip = Request::createFromGlobals()->getClientIp();

$time_start = date("Y-m-d");
$time_end = date("Y-m-d");
// 获取当天的IP
$model = Survey::where('ip', $ip)->whereBetween('created_at', [$time_start . ' 00:00:00', $time_end . ' 23:59:59']);
// 限制用户提交次数
if (($model->count())>=3) {
    return [
        'code' => 205,
        'data' => '',
        'msg'  => '今日提交次数已达上限!'
    ];
}

 

posted @ 2021-11-22 16:20  柠七。  阅读(190)  评论(0)    收藏  举报