Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wdridder's avatar

Only posting x times a minute

I have a forum and want to block people from posting to much for example --> stop them from posting more then 6 times a minute. How can I create this? Is there a quick and nice way to handle this?

0 likes
3 replies
STEREOH's avatar

You could count the number of posts the user created in the last minute and if it's > 6 redirect back.

$dt = CarbonImmutable::now();
$countPosts = $user->posts()
           ->whereBetween('created_at', array($dt->subMinute(), $dt))
           ->count();

Edit : I realize that whereBetween is totally unnecessary since I don't believe your users are able to post in the future. You can just fetch every post with a created_at > now minus 1 minute.

$dt = new Carbon('last minute');
$countPosts = $user->posts()
           ->where('created_at', '>', $dt)
           ->count();
1 like
wdridder's avatar

And how to create this but then for multiple tables... so "if 6 items in tables x, y & z in the last minute, then redirect back".

Please or to participate in this conversation.