Hello,
For some of my Models, I need to upload one or more files and store them within my Model: i.e. I need to upload an avatar for the User profile, or an image for each News I create, or attach a .pdf (i.e. a brochure) and a picture for a Product model.
Uploading a file and store its path within a Model it's a trivial task, but this is only half of the work and that's where situation get complicated: i.e. I'd need to:
- "slug" the filename: change 'My Product Picture.jpg' to 'my-product-picture.jpg'
- check if there's not yet a 'my-product-picture.jpg' file and, in case, change the new uploaded filename to 'my-product-picture_2.jpg' (and so on for subsequent uploads)
- create thumbnails and cache them
- if I'm updating a Model, well, delete old file(s) - and related thumbnails - before uploading new one(s), so I don't have "orphaned" files in storage
- deal with errors: if user tries to upload a file bigger than upload_max_filesize, well, tell him what's the problem (instead of the current generic 'The :attribute failed to upload.' message that ships with Laravel 5.3)
Since Laravel doesn't manage all these tasks (as far I as know), I created a custom UploadTrait that takes care of (almost) all these things, but it's quite a mess.
I'm sure that I ain't the first who has to deal with these tasks, and I was wondering if there is a Laravel package that can simplify the work: do you know any f these, or do you have suggestions?
Thanks