I'm working on a project where every user is able to add multiple product images. I'm using a single form to submit the product which does 2 things in ProductController@store which are creating new product + creating images belongs to this product in Images table.
The important part is that I want to allow users to upload total of 10mb of images per product. So mainly I want to validate total files size of the array of images the user trying to update.
@Sinnbeck I was thinking to start my project with limiting the overall size of images and leave it up to the user to upload whatever they want. But it's actually a very good idea to optimize imagies over 1mb, yet I have zero knowledge on how to accomplish that, I still have to research how to do that.
@Sinnbeck well, if you got a minute I just have a small question. I already manually wrote the logic and made my migrations but I just wanted to see if this is the best way to do it. I have Products Model which hasMany ProductImage, I'm using the same form to submit a post request to ProductController@store to validate both Product details and ProductImage files and within the same action Im creating a product and using ProductImage::Create() to create my images. So I don't think I will ever need controller for ProductImage because I'm using Product controller.
Is that considered a bad code or bad practice? If you think this deserves it's own thread with code snippets just let me know. Thank you so much for your time!
@MooseSaid that sounds completely fine. Perhaps I would later add a controller for adding and deleting images on an existing product. But what you have now sounds like how I would do it to
@MichalOravec I thought I included that. Fixed.
Is that the only reason why you think it's bad? Is it a bad practice or not well written? Anyway, thanks!