Polymorphic Eloquent relationships with namespaces

后端 未结 2 1705
别那么骄傲
别那么骄傲 2020-12-03 08:26

I\'ve tried to implement polymorphic relationships. They work perfectly... However, I\'m trying to reduce my database size as much as possible so... I\'ve this



        
2条回答
  •  囚心锁ツ
    2020-12-03 09:08

    Since Laravel 4.1, inside your model (in this case Company and People) you can set the protected property $morphClass to whatever you want.

    Now in your table you can store the type without the namespace:

     |  id  |  realatable_type  |  relatable_id
     |  2   |  Company          |  13
    

提交回复
热议问题