Hello all. This is my first project using Laravel and I'm really enjoying the experience. Especially how it makes you consider different approaches to solving problems. To that end I've reached a point where I'm unsure what the best option is. I've done some reading on the matter and watched a few Laracasts, but can't decided with option to take and would appreciate any feedback / opinions.
I have two models; Brief which represents a project brief and Designer which represents a designer.
The Brief model requires the end-user to save some text data, upload some images in bulk, and a single image of a building floor plan.
The Designer model requires the end-user to save some text data, upload some images in bulk, and a single image of an avatar.
For both models I have completed the saving of text data and the uploading of images in bulk thanks to Dropzone.js (which is amazing).
Each image uploaded creates an entry in a database table. Saving usual things like filename, date uploaded, and file size. Also saving the ID of the Brief/Designer the images were uploaded to as well as the model's class i.e. App\Brief. As you no doubt guessed, it's polymorphic so in Laravel I can just type: $brief->attachment; to receive a collection of all the image for that brief. Same is true for designer or any future model I add images to in the future.
This is great for the images uploaded in bulk. But where I'm stuck is the instance of the single image i.e. floor plan or avatar. What do you think would be the best way to associate a single image to the floor plan or avatar field?
-
Save the path to the uploaded image in the Brief / Designer table and abandon the image table for all one-off images.
-
Save the ID of the uploaded image from the image table into the Brief / Designer table. Then write a method on the Brief / Designer model i.e. getFloorPlan().
-
Save an additional flag to the image table i.e. "floorplan". Then write a method on the Brief / Designer model i.e. getFloorPlan().
Or is there another way I'm overlooking?