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

johnDoe220's avatar

create relationship between tables post podcast education with tags

Hello I have three tables post podcast Education I have and I want to connect these to the tag table with relationships What I've done now is create a many to many relation to the tag table for each of my tables. To make this question more understandable, my tables are implemented as follows (for now).

post migration for example

id - title - slug - image - created_at - updated_at

tag migration for example

id - name - created_at - updated_at

pivot table (post-tag)

id - post_id - tag_id - created_at - updated_at

It works great now But the problem is, my tables have a similar structure, and I did the exact same thing with another table. for exaple . pivot table (podacst-tag)

id - podcast_id - tag_id - created_at - updated_at

pivot table (education-tag)

id - education_id - tag_id - created_at - updated_at

And I think there's a better way, thank you

0 likes
3 replies
Yarad's avatar

Maybe you can repeat eloquents "Polymorphic Relationships" logic and organize it like this: example

Where "model_type" will be mapped to your models:

  • App\Post
  • App\Podcast
cipdassignment's avatar

It sounds like you’ve structured your database well by setting up many-to-many relationships between your post, podcast, and education tables with the tag table. This approach allows flexibility, as each record can be linked to multiple tags and vice versa. You just need proper join tables for each relationship to keep everything normalized. For more structured help.

kevinbui's avatar

@cipdassignment This is a three-year-old thread, the author probably has figured it out by now.

This is the classic polymorphic many-to-many relationship. And Laravel docs provides exactly the same scenario.

Please or to participate in this conversation.