I think the best solution is doing something with JS. Another solution would be keeping the count in a session or cookie or whatever. You can higher up the count before you start the upload and check if the count has been reached. You can also store that in the database, but that might be a bit slower!
Dec 20, 2017
4
Level 6
Issue when the SQL query is slower than multiple requests
Hi.
I have a page where an user can upload some photos.
Imagine that the limit is ten photos per user. I use dropzone to upload multiple photos, and it runs one request per photo upload.
The problem is that when I check the number of the photos inthe request, when the next request "starts", sometimes the query has not finished, so the user "sometimes" can upload more than ten photos. (I know I could do some front-end validation, but does not solve my problem.
// PhotoController
public function store()
{
// check...
if (request()->user()->countPhotos() >= 10)
{
return response()->json([
'message' => 'You cannot upload more than 10 photos'
], 403);
}
// upload the photo...
}
What can I do to solve this?
Please or to participate in this conversation.