对于system_files表中的attachment_type字段,会自动生成带有类名的字符串。如何设置指定类字符串?
现在看起来像这样:
public $attachOne = [
'main_photo' => [
'System\Models\File',
'delete' => true,
]
];
我在这里假设,但我猜您不希望将完整的类存储在
attachment_type
表的 system_files
列中。
您可以做的是在插件的
boot()
文件的 Plugin.php
方法中定义变形贴图。
因此,如果您在
October\Shop
命名空间中有一个插件,并且具有 Product
模型,则可以执行此操作。
// Plugin.php
<?php
namespace October\Shop;
use System\Classes\PluginBase;
use October\Rain\Database\Relations\Relation;
class Plugin extends PluginBase
{
public function boot()
{
Relation::morphMap([
'product' => \October\Shop\Models\Product::class,
]);
}
/** The rest of your plugin.php file **/
}
您可以在文档中阅读相关内容。