christiangerdes's avatar

Upload multiple images causes problems

I'm using L5 and dropzone.js in this project.

Using dropzone.js I can upload images parallel and then let the backend handle everything. So when I upload multiple images at the same time the backend runs into some trouble.

Let's say I were to upload 3 images to one ad. Then 3 requests are made, which make the response time faster because you doesn't have to wait for all of them to upload. But... The first image is handled a bit different. You see, the first image should have a field checked in db that indicates that the image is the primary image. The rest is just set to false.

Here is the code:

$importance = Image::where('ad_id', $ad->id)->count();

$image = Image::create([
    'ad_id'         => $ad->id,
    'importance'    => ($importance == 0) ? 1 : 0,
]);     

I know that I should wire the image to the ad table differently, but thats not the focus right now. The problem is that multiple images set the importance field to true. I guess this has something to do with to images hitting the server at the same time??

Help me. Thanks! :D

0 likes
2 replies

Please or to participate in this conversation.