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

2Pr3cise's avatar

[L5.2] DB-design question (morph's and pivots)

Hi,

based on my earlier question (https://laracasts.com/discuss/channels/eloquent/l52-pivot-table-with-additional-fields-dates), I now have a similar problem:

I have the following models:

  • Employee
  • SchoolGraduation
  • UniversityGraduation
  • SecondEducation
  • and some other 'graduation'-type models.

Each Employee can have multiple Certificates which basically are the above listet types. So I think, a polymorphic relation is what I want to use here (right?). But, I also need to add some additional information to the pivot, like a completion field and a comment field.

Basically, the above listed 'graduation'-type models are simple objects with a name and a description field. And a given Employee can have several of them, with the extra information of when they get it and an optional comment (thus, I want to have the above mentioned extra fields on the pivot).

First of all, does it make sense? Or do I miss/oversee something?!

If my thoughts are right so far, is it possible to use something like this with polymorphic relations? If so, would this be a regular polymorphic relation or a many-to-many polymorphic relation? And how do I use a custom pivot on this polymorphic relation?

Thanks in advance for any tips :)

0 likes
2 replies
2Pr3cise's avatar

I should have mentioned, that a Certificate is one of the above mentioned types. E.g.

  • An Employee can have 0..n SchoolGraduation certificates
  • An Employee can have 0..n UniversityGraduation certificates
  • An Employee can have 0..n SecondEducation certificates
  • and so on

this is, why I think I have to use a polymorphic relation in order to set the type (e.g. certificate_id and certificate_type in the polymorphic pivot table)

And I need the additional fields (completion_date) in order to display each Certificate of an Employee in their asc/desc order.

usama.ashraf's avatar

Are the three types of certificates very different in structure? If so, I don't see a problem with your approach.

But it seems to me that you might be able to 'merge' all the certificates in one table and have some field(s) that describe them.

Please or to participate in this conversation.