lundi 1 février 2016

Eloquent relationship based on column

I have a table called BLOCKS, with an enum column TYPES, with options: HTML and Gallery.

So the idea is to have an OBJECT_ID (int) column, which will reference to a table depending on the selected TYPE.

The relationship would be named CONTENT and would retrieve its content depending on the selected TYPE.

  • If the TYPE is HTML, the object_id will reference to a PAGES table (which has a content column and so).
  • If the TYPE is Gallery, the object_id will reference to a GALLERIES table (with different properties of course).

How can this be achieved?

Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire