DropzoneJS does multiple POSTs for each image/file. Just save it to the database like normal?
Hmm, are you saving it into some array in the database? Why not have a hasMany() or belongsToMany() relationship?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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 or to participate in this conversation.