Dec 13, 2016
0
Level 1
Laravel and Dropzone in normal form
I cant get the image on dropzone getting null value when i die dump $files... sorry for my bad english thank you i hope someone help me :)
##Dropzone JS
Dropzone.options.myDropzone = {
autoProcessQueue: false,
uploadMultiple: true,
addRemoveLinks: true,
maxFilesize: 7,
maxFiles: 8,
previewsContainer: '#dropzonePreview',
clickable:'#myDropZone',
init: function() {
var myDropzone = this;
this.element.querySelector("#submit").addEventListener("click", function(e) {
e.stopPropagation();
myDropzone.processQueue(); // this will submit your form to the specified action path
});
}
}
##View {!! Form::open(array('url'=>'client/addproduct','class'=>'dropzone','id'=>'myDropzone','enctype'=>'multipart/form-data')) !!} Product Name
<div class="form-group">
<label for="Product Price">Product Price</label>
<input type="text" class="form-control" id="price" name="price" placeholder="Regular Price" required maxlength="9" >
<p class="help-block">Note! no comma, no decimal places and not starts from 0, example: 5000 </p>
</div>
<div class="form-group">
<input type="text" class="form-control" id="price_sale" value="0" name="price_sale" placeholder="Sale Price" required maxlength="9">
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea maxlength="600" class="form-control" type="textarea" id="description" name="description" placeholder="Description" rows="7"></textarea>
<span class="help-block"><p id="characterLeft" class="help-block">You have reached the limit</p></span>
</div>
<div class="form-group">
<label for="product-tag-select">Tags</label>
{!! Form::select('tags[]',$tags, null, ['id' => 'product-tag-select','class' => 'form-control', 'multiple', 'style' => 'width: 100%;']
) !!}
<p class="help-block">type to search keyword tags and press enter</p>
</div>
<div id="myDropZone">
<div class="dz-message" data-dz-message><span>To Upload Click or Drag and Drop Image here</span></div>
<div id="dropzonePreview">
</div>
</div>
<button type="submit" id="submit" name="submit" class="btn btn-success pull-right">Add Product</button>
{!! Form::close() !!}
##Controller
public function postAddproduct(Request $request)
{
$price = str_replace(',', '', Input::get('price'));
$this->validate($request, [
'product_name' => 'required',
$price => 'integer|min:2|greater_than:price_sale',
'description' => 'required',
'tags' => 'required',
]);
$random_id = Uuid::generate(4);
$slug = str_slug(Input::get('product_name'));
$product = new Product;
$product->id = $random_id;
$product->slug = $slug;
$product->product_name = Input::get('product_name');
$product->category = "hello";
$product->sub_category = "hello";
$product->price = $price;
$product->price_sale = 0;
$product->description = Input::get('description');
$product->username = Auth::user()->username;
$product->save();
$products = Product::Find($product->id);
$products->tags()->attach(Input::get('tags'));
$files = Input::file('file');
dd($files);
$uploadcount = 1;
foreach ($files as $file) {
$random = str_random(10);
$product_image = new ProductImage;
$filename = time() . '_' . $random . '.' . $file->getClientOriginalExtension();
$path = public_path('img/products/' . $filename);
Image::make($file->getRealPath())->resize(1200, 630)->save($path);
$product_image->image = 'img/products/' . $filename;
$product_image->product_id = $random_id;
$product_image->sequence = $uploadcount;
$uploadcount++;
$product_image->save();
}
return redirect()->back()->with(['message' => 'Product has been successfully added', 'message_class' => 'alert alert-success fade in col-lg-offset-1']);
}
Please or to participate in this conversation.