与口才的三方枢纽连接

问题描述 投票:0回答:1

我们有可以通过mysql创建的自定义字段,这些字段由模块“拥有”(例如:Opportunities-module需要“潜在销售”字段,而User-section需要性别字段(选择3个选项)。

[使用Laravel 6雄辩,我试图获取:

  1. 所有机会
  2. 和custom_fields,其中类别='机会'
  3. 和相关的custom_fields_values通过枢轴。
  4. ,然后将它们添加到集合中的“相关”数组中。这样我就可以轻松做到:

$opportunity->custom_field[x]->custom_field->name
$opportunity->custom_field[x]->custom_field_value[x]->value

DB:

custom_fields: 
id, name, category (opportunity, client...), type (text, number, select, radio)

custom_field_custom_field_value (pivot):
custom_field_id, custom_field_value_id, parent_id (=id of the "parent" opportunity or client...), selected

custom_field_values:
id, value

我很想让自己开始,但我百分百地陷入困境-甚至不知道从哪里开始使用归属感等...或者这完全可行...

我们有可以通过mysql创建的自定义字段,这些字段由模块“拥有”(例如:Opportunities-module想要一个“潜在销售”字段,而User-section想要一个性别字段(...

php mysql laravel join eloquent
1个回答
0
投票
class CustomField extends Model
{
    public function values()
    {
        return $this->belongsToMany(CustomFieldValue::class);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.