【问题标题】:polymorphic relationship that is of belongsToMany type so I can attach single record to multiple polymorphic records属于 belongsToMany 类型的多态关系,因此我可以将单个记录附加到多个多态记录
【发布时间】:2017-08-06 23:54:31
【问题描述】:

我已经创建了表格设置和模型设置。

这是表格的定义:

        $table->bigincrements('id');
        $table->string('has_settings_type');
        $table->biginteger('has_settings_id')->unsigned();
        $table->string('key');
        $table->string('value')->nullable();
        $table->string('type')->default('string');

这允许我将设置附加到单个模型。但是我想出了一个用户案例,我想将设置附加到多个模型而不仅仅是一个模型,而且它仍然必须是多态关系。

我知道不使用多态时如何创建belongsToMany,但我不确定使用多态时如何设计表,我需要belongsToMany。

有什么建议吗?

【问题讨论】:

    标签: laravel laravel-5 laravel-5.3


    【解决方案1】:

    我想通了。好像 Laravel 支持这种东西。

    答案在这里:

    https://laravel.com/docs/5.4/eloquent-relationships#many-to-many-polymorphic-relations

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多