Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dammyammy's avatar

Did He try to include this?

<script type="text/javascript">
             $(document).ready(function(){
                 $("div#dropzone").dropzone({
                         url: "/product/upload",
                         addRemoveLinks: true, 
                         uploadMultiple: true, // Adding This 
                         dictRemoveFile: 'X (remove)'
                 });
             });
</script>

or adding this?

<div id="dropzone" name="images" multiple>
          Drop files here
 </div>

Because I didn't notice his code specifying he wants to upload multiple files.

Storing in the database should be pretty straight forward.

unitedworx's avatar

You should setup barryvdh/laravel-debugbar on your project which will help you easily see the ajax requests and responses you get so you can easily debug what's going on and solve your issues much faster. It's the first thing I install and help a ton! On the right side of the debug bar you get a drop down with th Ajax requests your app just made and you can select then to see exactly the data sent the the response you received back.

https://github.com/barryvdh/laravel-debugbar

Hope this helps

2 likes
bashy's avatar

Debug bar is nice but sending manual requests to URLs in Postman is better than filling out forms or doing testing. Also adds more files to load into your website/memory

theUnforgiven's avatar

I still get

error: {type:ErrorException, message:Undefined property: Illuminate\Database\Eloquent\Collection::$images,…}
file: "/home/vagrant/code/engine/app/controllers/ProductController.php"
line: 110
message: "Undefined property: Illuminate\Database\Eloquent\Collection::$images"
type: "ErrorException"

Even after adding

<div id="dropzone" name="images" multiple>
        Drop files here
</div>
theUnforgiven's avatar

I have

Input::get('images');

To try and add to the DB but nothing and still the error above.

bashy's avatar

Is images an input field or what? Input::get() isn't for files

theUnforgiven's avatar

In the DB it's TEXT

In the form it's

<div id="dropzone" name="images" multiple>
        Drop files here
</div>
theUnforgiven's avatar

So yeah it's not an input, therefore can I do Request::get(); instead

bashy's avatar

If it's a file you're trying to pick up

$images = Input::file('images');

This will be an array if it's sending them in one POST request. If not you can do each request on its own. Please check the network tab... it tells you EVERYTHING :)

theUnforgiven's avatar

Now i get a different error:

error: {type:Symfony\Component\Debug\Exception\FatalErrorException,…}
file: "/home/vagrant/code/engine/app/controllers/ProductController.php"
line: 106
message: "Call to a member function getClientOriginalName() on a non-object"
type: "Symfony\Component\Debug\Exception\FatalErrorException"
bashy's avatar

That means it's not picking anything up on $file. Have you tried returning what's being sent to $file?

This is pretty basic PHP debugging

This is what I use on my one

public function postUpload()
{
  $input = Input::all();

  if ( ! \Media::isValidUpload($input))
  {
   return Response::json(array(\Media::$errors->all()), 400);
  }

  $file = Input::file('file');

  $destinationPath  = 'uploads';
  $file_label   = Input::get('file_label');
  $original_filename    = $file->getClientOriginalName();
theUnforgiven's avatar

Yes I know, just not sure what it is, the same code is what I used previously on another project. But I will try your method.

All I want is to get the JSON response then save it to the DB.

bashy's avatar

What do you mean by "get the JSON response"? get it to where?

You just return something like this on error

$image = new Image();
$somefield = $image->somefield;

if ($image->save())
{
    return Response::json('success', 200);
}
else
{
    return Response::json('Error saving image to database', 400);
}
theUnforgiven's avatar

In my controller I have:

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

How do I get this response and save to DB then?

As the upload and create product are two different methods within my controller

bashy's avatar

You will need to listen for the event - success in JavaScript section of Dropzone JS

theUnforgiven's avatar

Or I may just start again with it and not have 2 methods and just incorporate into one.

bashy's avatar

Check the docs on their website, has all the events listed ;)

leitom's avatar

Try grab the json in the controller like this:

Request::json()->all();

theUnforgiven's avatar

Thanks @leitom I tried that and still doesn't store the 2 or more images I select in the dropzone area.

bashy's avatar

Donezone JS does single POST requests PER file (at least on my setup it does). There might be a setting to change that but I haven't looked into it as single requests is fine for my needs.

theUnforgiven's avatar

Dunno, I'm looking into either building something from scratch or just starting again, maybe i have some conflict somewhere, so starting with it again may be the best option.

phaberest's avatar

Hi @lstables , I'm trying to get the same task done...have you found out how to get it to work?

Previous

Please or to participate in this conversation.