【发布时间】:2017-03-29 06:05:33
【问题描述】:
我需要向 Laravel 中的数据库提交一个包含多个文件的表单,每次填写表单时都会出现此错误
SQLSTATE[42S22]:未找到列:1054 '字段列表'中的未知列 '0'(SQL:插入到
add_file(0) 值({"name":"Opeyemi Adam","description ":"谢谢兄弟","attach":[["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));
}
不知道字段列表来自哪里
【问题讨论】:
-
删除了 SQL Server 标签,因为错误输出来自 MySQL。
标签: php mysql laravel laravel-5