Also calling the dropzone on a div with a ID of dropzone
<script>
$(document).ready(function () {
$("div#dropzone").dropzone({ url: "/admin/products/images" });
});
</script>
Hi guys,
I'm using DropzoneJS to upload multiple images, but the page this is on is for products and the route assigned, doesn't know the product ID yet as that doesn't happen until the user clicks save.
Routes
post('products/images', 'ProductsController@images');
resource('products', 'ProductsController');
ProductRepo:
public function createNewProduct($request)
{
$product = new Products;
$product->product = $request->input('product');
$product->description = $request->input('description');
$product->sku = $request->input('sku');
$product->price = $request->input('price');
$product->tax = $request->input('tax');
$product->shipping = $request->input('shipping');
$product->status = $request->input('status');
$product->save();
return $product;
}
Controller:
public function store(NewProductRequest $request, EloquentProduct $product)
{
$product->createNewProduct($request);
alert()->success('Success', 'Product successfully created');
return redirect('admin/products');
}
Then I have this method for the image uploading part. This is the part I'm not sure on how to save it the database without knowing the newly created product ID.
public function images(Request $request)
{
$file = $request->file('file');
$name = time() . $file->getClientOriginalName();
$file->move('uploads/products', $name);
// Not sure what to do here to save the images to to the images db and assign
// the correct newly created product ID
}
Any help greatly appreciated.
Please or to participate in this conversation.