Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

calvincani's avatar

Link pictures in a database table to a user profile

I'm busy building this app that will allow users to upload pictures they have taken, to their profile. Like a gallery for their profile. so multiple images on one profile. The problem is I need these pictures to be in their own table so I can have the website display all the pictures in that table randomly on the site. So first off how do I allow a person to upload multiple pictures to their profile? Oh and a profile is separate from the user account. every user account can only have one profile, but one profile can have many pictures uploaded by the profile owner? I am fairly new to Laravel and PHP so any help will be greatly appreciated. Thank you in advance.

0 likes
2 replies
martinbean's avatar

@calvincani You can just have an images or profile_images table where you store the image paths, and also a foreign key pointing to the profile ID the image belongs to. Then showing random images is just a case of pulling random rows from the table.

calvincani's avatar

@martinbean thank you and I presumed that would be the way to do it. I'm a little inexperienced and so it's more the implementation of this that I am struggling with. I created a profile migration and I added the extra fields for the profile but how do I allow a profile to have multiple images. I mean what type of field is required for the user to upload multiple images to his/her profile and then do I need to specify in the Profile controller the profile is allowed to have multiple images? This is all very new to me. Also how do I make it that on the profile edit template that the user can upload more than one at a time? Appreciate the help

Please or to participate in this conversation.