在前端表单中,我有多个文件上传字段。所以在提交表单时,我在数据库中创建了一个新记录,然后尝试将多个图像附加到它,如下所示:
模型类中指定的画廊的关系
public $attachMany = [
'gallery' => 'System\Models\File',
];
前端表单处理
function onCreate() {
$data = post();
$newRecord = Record::create($data);
if (Input::hasFile('gallery')) {
$newRecord->gallery()->create(['data' => Input::file('file_input')]);
}
}
前端表单 HTML
<form method="POST" accept-charset="UTF-8"
data-request="onCreate" data-request-files data-request-flash>
<input accept="image/*" name="gallery" type="file" id="gallery" multiple>
</form>
但是,我不断收到以下错误:
SQLSTATE [HY000]:一般错误:1364 字段“磁盘名称”没有默认值
设置$guarded = []
并vendor/october/rain/src/Database/Attach/File.php
没有帮助。