gpt4 book ai didi

php - Laravel SQLSTATE[42S22] : Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into `add_file` (`0` )

转载 作者:行者123 更新时间:2023-11-29 07:08:49 26 4
gpt4 key购买 nike

我需要向 Laravel 中的数据库提交一个包含多个文件的表单,每次填写表单时都会出现此错误

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into add_file (0) values ({"name":"Opeyemi Adam","description":"Thanks bro","attach":[["CRITICAL TECHNICAL OBSERVATIONS.doc"]]}))

下面是模型

class AddFile extends Model{
protected $table = 'add_file';
protected $fillable = ['name', 'description', 'attach'];
}

Controller

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));


}

不知道字段列表来自哪里

最佳答案

看起来您正在尝试将数组 ($attach_file) 直接保存到某种文本列中。您需要首先将其更改为字符串才能执行此操作 - 例如通过 serialize()json_encode()

关于php - Laravel SQLSTATE[42S22] : Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into `add_file` (`0` ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40608456/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com