1
我想让用户最多只能发布每分钟1条评论。限制评论
我试过简单地使用throttle
中间件,它不工作。我仍然可以每秒发表评论。
路线代码:
Route::post('comment/{id}', '[email protected]')->name('comment')->middleware('throttle');
控制器代码:
public function comment($id)
{
$this->validate(request(), [
"body" => "required",
]);
$jersey = Jersey::findOrFail($id);
$comment = new Comment;
$comment->user_id = auth()->user()->id;
$comment->jersey_id = $jersey->id;
$comment->body = request()->input('body');
$comment->save();
activity()->by(auth()->user())->withProperties($comment)->log('Commented');
request()->session()->flash('status', 'Comment submitted!');
return redirect()->route('concept', $id);
}
如何让这个它会闪烁而不是保存如果用户尝试发布超过1个评论的错误每分钟?
油门中间件是Laravel的核心功能。 – kjdion84