I'm creating an Image Editing order system, where a user can upload multiple images by DropZone & Laravel. I want to implement after successful image upload image information save to database & send User an email notification. Then redirect to another page with session message. My code sends more than 1 email every time when saving data to the database. But I need to send an email when all image data successfully saved to the database. Here my code: Here is my Full Controller Code:

 public function doImageUpload(Request $request) {
      //get the file from the post request
      $file = $request->file('file');

      //set the  file name
      $filename = $file->getClientOriginalName();
      //move the file to correct location
      $order_number = $request->input('oid');
      $username = Auth::user()->username;
      $path = 'orders/'. $username .'/' . $order_number;
      if(!file_exists($path)){
          mkdir($path, 0777, true);
      }

      $file->move($path, $filename);

      //save the multiple/single file details to database
      $order = Order::find($request->input('order_id'));
        $order->images()->create([
          'order_id' => $request->input('order_id'),
          'file_name' => $filename,
          'file_size' => $file->getClientSize(),
          'file_mime' => $file->getClientMimeType(),
          'file_path' => $path . '/' . $filename,
          ]);

         Session::put('success','Your order has been submitted successfully.');
         $data = array(
        'fullname' => $order->user->fullname,
        'email' => $order->user->email,
        'order_number' => $order->order_number
    );
    Mail::send('emails.order-submit', $data, function($message) use ($data) {
        $message->from('test@gmail.com');
        $message->to($data['email']);
        $message->subject('Order Submit');
    });
}

DropZone Configuration Code:

Dropzone.options.uploadImages = {
    autoProcessQueue: false,
    maxFilesize: 2048,
    uploadMultiple: false,
    parallelUploads: 100,
    acceptedFiles: 'image/*',
    addRemoveLinks: true,
    dictRemoveFile: 'Remove',

    init: function() {
    var submitButton = document.querySelector("#submit-images")
        addImages = this; // closure

    submitButton.addEventListener("click", function(e) {
        e.preventDefault();
        e.stopPropagation();         
      addImages.processQueue(); // Tell Dropzone to process all queued files.
    });
    this.on("addedfile", function(file) {
      // Show submit button here and/or inform user to click it.
    });

    this.on("success", function() {
         if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
        window.location.href = 'http://localhost:8000/user/orders/manage/';
      }
    });
    }
};

asked 19 Jul '17, 16:08

fsuuaas's gravatar image

fsuuaas
311

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×53
×3

question asked: 19 Jul '17, 16:08

question was seen: 161 times

last updated: 19 Jul '17, 16:08