kickthemooon's avatar

use response in jquery and js loop

So I am using dropzone to upload some images, my controller that i send the images to looks likes this (and i am using laravel media library ):

public function galleryUpload(Request $request, $id)
    {
        $offer = Offer::find($id);

        $offer->clearMediaCollection($id);

        $offer->addMedia($request->file('file'))->toCollectionOnDisk($id, 'media');

        $urls = $offer->getMedia('64')
            ->keyBy('id')
            ->transform(function (\Spatie\MediaLibrary\Media $media) {
                return $media->getUrl();
            });

        return $urls->toArray();
    }

the response i get looks like this:

{50: "/media/50/twitter cover photos for new year 2016.png", 51: "/media/51/174920-1280.png",…}

50: "/media/50/twitter cover photos for new year 2016.png"
51: "/media/51/174920-1280.png"
52: "/media/52/instagram-followers.jpg"

Now I would like to appent this:

<div class="col-lg-2 col-md-4 col-xs-6 thumb">
       <img class="img-responsive" src=" // the values of the response array //" alt="">
       <div class="galleryremovebutton">
          <a href="/delete/ the keys / ids of the response array " class="btn btn-danger" role="button">Izbrisi sliku</a>
       </div>
 </div>

as a loop to this:

<div id="galleryimgs" class="row">

I want to do that on the dropzone complete event so here:

Dropzone.options.myGalleryDropzone = {

            paramName: "file", // The name that will be used to transfer the file
            maxFilesize: 1, // MB
            parallelUploads: 8,
            complete: function () {
                HERE
            }
        };

I mean I could do something likes i think:

function (response) {
                    but im not sure how to reference the keys and the values from the response
                    }

Any ideas, suggestions?

0 likes
0 replies

Please or to participate in this conversation.