多客户端应用程序的自定义字段设计

Custom fields design for multiclient application

我有一个与应用程序设计相关的问题。我有一个供 9 个客户使用的电子商务应用程序。每个客户端都有相同的应用程序副本和不同的前端模板。应用程序是在 laravel 下设计的,它会在每个客户服务器上更新以保持最新。所以每个应用程序都有相同的后端("engine")、相同的数据库设计等

问题是两个客户想要自定义字段用于 CRUD 页面。使用当前的更新机制,每个客户端都会得到那些不是我想要的字段。

我一直在考虑向数据库添加单独的 table 以保留所有字段的配置 - 就像 table 列的映射。因此,当使用应用程序时,控制器将调用配置 table 以获取字段列表并将它们放在视图中。

+---+---------------+-------------------+------------+
|id |controller     | field_name        |field_type  |
+---+---------------+-------------------+------------+
| 1 | products      | price_retail      | integer    |
| 2 | manufacturers | name              | varchar    |
| 3 | manufacturers | logo              | varchar    |
| 4 | manufacturers | custom_for_client | integer    |
+---+---------------+-------------------+------------+

这是个好主意吗?

不知道你打算用这些"fields"做什么,我只能提出建议。

您是否考虑过使用 json 列来存储并非适用于所有用户的字段的数据?

数据库迁移

...
$table->json('meta')->nullable();
...

型号

...
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        ...
        'meta' => 'array',
        ...
    ];
...

然后您可以访问此 json 对象中的 "fields",如下所示:

$model->meta['column'];

或者像这样迭代:

collect($model->meta)->each(function ($column) {});

https://laravel.com/docs/7.x/eloquent-mutators#array-and-json-casting