you've got it nailed! user->experiences is a great name for it.
- jobs
- courses
- volunteer work.
do you need any specific help
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I'm looking for some advice on structuring a relationship of sorts.
I have three tables; users, projects, and jobs
Set up roughly like so:
users
id - integer
name - string
projects
id - integer
name - string
date - date
jobs
id - integer
name - string
date - date
Each user can have multiple projects and jobs assigned to them, and likewise a project or job can be linked to one or many different users.
That can easily be achieved with simple many-to-many relationships. However, my caveat is that I want to be able to access all of the projects and job, for a user, under the same property, experiences, rather than having having to call two different properties. There are several reasons, including the need to show them in a list together, sorted by date.
Instead of this:
@foreach($user->projects as $project)
... some code here ...
@endforeach
@foreach($user->jobs as $job)
... some code here ...
@endforeach
I want to do this:
@foreach($user->experiences as $experience)
... some code here ...
@endforeach
I'm thinking a polymorphic relationship would be best, but I can't figure out the best way to structure the relationship, and if I potentially need an intermediary experience model.
Maybe something like:
experiencables
experience_id - integer
experiencable_id - integer
experiencable_type - string
With data something like:
| experience_id | experiencable_id | experiencable_type |
| ------------- | ---------------- | ------------------ |
| 1 | 1 | \App\Project |
| 1 | 1 | \App\Job |
| 2 | 1 | \App\Project |
| 2 | 2 | \App\Project |
| 2 | 1 | \App\Job |
And then a user->experiences many to many relationship`.
I will also be wanting to add more "experiences" that link to the User in the same way that projects and jobs do.
Any help would be appreciated.
Please or to participate in this conversation.