Laravel 中的自定义多态类型

问题描述

我正在处理多态关系并创建了一个多态表,其中的列类似于

posts -:
   | id(integer) | title(string) | body(text) |

videos -: 
   | id(integer) | title(string) | url(text) |

comments -: 
   | id(integer) | title(string) | commentable_id(integer) | commentable_type(string) |

认的 commentable_type 分别是 App\Models\PostApp\Models\Video

我不想将这些值用于 commentable_type 想要一些自定义,找到了一种使用 morphMap 的方法,例如 -

use Illuminate\Database\Eloquent\Relations\Relation;

Relation::morphMap([
    'posts' => 'App\Models\Post','videos' => 'App\Models\Video',]);

寻找一些其他的解决方案,比如一些可以在模型中使用的标志或方法来实现一些结果

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)