Support the ongoing development of Laravel.io →
Database Eloquent

I have two tables. One is People. The second is Files. Files contains all uploaded files through an admin. The entries on Files can belong to People or other models that also use files. The basic table structure is below.

People

  • id
  • name
  • bio
  • small_image_id
  • large_image_id

Files

  • id
  • filename

Is it possible to use a relationship to get both files from the Files model with the People model? So, when all said and done I need to query a person a link the two files from the Files model. Or, is this better achieved with a regular query using joins?

Last updated 3 years ago.
0

Hi, What you have here is a many-to-many relationship You can check Many To Many

Last updated 3 years ago.
0

Thanks for the reply. One more question. After reading my post, I'm not sure I was 100% clear on the relationship of the Files. The files that belong to the People only belong to People. However, there are files that belong to other Models. So, let's say I also have a Location model. Those files only belong to Locations and not People.

Does that make sense? Does that change anything? Or, should I still be looking at Many to Many. (which I'm doing now on my end.)

Last updated 3 years ago.
0

If Files for Location and Files for People share model, you can without problem set it as many-to-many or even poli relation.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.