Using Dropzone JS to do multiple uploads

Posted 4 years ago by theUnforgiven

Hi All,

Quick question I'm hoping someone can help me with. I'm using Dropzone.js to upload multiple images, but I'm unsure on how to then store the JSON response in the database (mysql)

I have a method called upload like so:

public function upload()
    {
        $user_id = Auth::user()->id;
        $file = Input::file('file');
        $fileName = $file->getClientOriginalName();

        $file->move(public_path().'/uploads/products/', $fileName);

        $products = Products::where('customer_id', '=', $user_id);
        $products->file = array_merge($products->images_array, [$fileName]); // If not, this will work
        $products->save();


        return Response::json(array('filelink' => '/uploads/products/' . $fileName));
    }

So in my 'store' method to store all the data from the form including these images how would I call it to save to db?

$product->images = $input['images'];  // doesn't work

The form is as follows:

{{ Form::open(['route' => 'products.store', 'class' => 'form-horizontal', 'files' => true]) }}

                <div class="form-group">
                     <div class="col-sm-2">Customer</div>
                         <div class="col-lg-3">
                             <input type="text" name="customer" class="form-control">
                         </div>
                </div>

                <div class="form-group">
                     <div class="col-sm-2">Description</div>
                         <div class="col-lg-3">
                             <input type="text" name="description" class="form-control">
                         </div>
                </div>

               <div class="form-group">
                     <div class="col-sm-2">Images</div>
                         <div class="col-lg-10">
                             <div id="dropzone" name="images">
                                 Drop files here
                             </div>
                         </div>
                </div>

{{ Form:close() }}

Anyone get any idea's, help etc?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.