Home how to create laravel polymorphic relation for tables with different type of primary key?
Reply: 0

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

Maulik Gangani
1#
Maulik Gangani Published in 2017-09-02 12:27:31Z

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?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.324772 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO