L
L
Lucius Mooning2018-06-13 15:20:52
Laravel
Lucius Mooning, 2018-06-13 15:20:52

How to set a limit on the number of entries for an arbitrary category?

Good afternoon!
The initial data is standard: there is a model aNewModel with fields id, user_id, content and a controller aNewController. The controller has a method for creating a new record create.
There are two questions: 1) Where and how is it better to set quantitative restrictions on the creation of new records (for one user) - in the controller in the store method or use middleware, or there are other ways. What do you recommend?
There are about 10 such controllers.
2) Where and how to make a limit on the number of new records per unit of time (for example, per second)?
The question is related to the need to protect against automation programs and bots.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yan-s, 2018-06-13
@honeymoonny

1. Probably immediately after or during the user rights check.
2. To limit the number of requests from the user per unit of time for a specific route, there is https://laravel.com/docs/routing#rate-limiting

L
Lucius Mooning, 2018-06-14
@honeymoonny

or is it better to remake the logic on FormRequest and do checks in authorize ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question