我需要向Laravel中的数据库提交一个包含多个文件的表单,每次填写表单时我都会收到此错误
SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列'0'(SQL:插入到add_file(0)值({“name”:“Opeyemi Adam”,“description”:“Thanks bro” ,“附加”:[[“CRITICAL TECHNICAL OBSERVATIONS.doc”]]}))
以下是模型
class AddFile extends Model{
protected $table = 'add_file';
protected $fillable = ['name', 'description', 'attach'];
}
调节器
public function submitform(AddFileFormRequest $request){
$destinationPath = storage_path('app/attachments/');
$attach_file = array();
$file = $request->file('attach');
if (!empty($file[0])){
foreach($file as $key){
$filename = $key->getClientOriginalName();
$key->move($destinationPath, $filename);
$attach_file[] = array($filename);
}
}
$form_content = new AddFile(array(
'name' => $request->get('name'),
'description' => $request->get('description'),
'attach' => $attach_file
));
var_dump($form_content);
DB::table('add_file')->insert(array($form_content));
}
不知道字段列表的来源
2 回答
尝试稍微改变你的代码,
或者你可以做到,
看起来你正在尝试将数组(
$attach_file
)直接保存到某种文本列中 . 您需要先将其更改为字符串才能执行此操作 - 例如通过serialize()
或json_encode()
.