samedi 2 septembre 2017

how to create laravel polymorphic relation for tables with different type of primary key?

In laravel documentation it shows how to create polymorphic relations. but In my case I would like to do it for different primary key column types.

for example, I am developing a social network for stock market. user can follow other users and user can also follow stocks.

Table: Users

  • id - increments (PK)
  • name - string
  • email - string

Table: Stocks

  • symbol - string (PK)
  • comapany_name - string

Table: Followings

  • id - increments (PK)
  • followable_id - what type? user_id is unsignedInt and symbol is string
  • followable_type - [possible values: Users/Stocks]

what is best way to solve this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire