【发布时间】:2017-01-02 15:43:50
【问题描述】:
我正在尝试插入数组,但出现错误:-
preg_match() 期望参数 2 是字符串,给定数组
我的表格如下:
{!! Form::text('description[]',null,['class' => 'input-field input-sm','v-model'=>'row.description']) !!}
{!! Form::text('log_time[]',null,['class' => 'input-field input-sm','v-model'=>'row.log_time']) !!}
我的控制器存储功能:
$this->validate($request, $this->rules);
$data = array();
foreach($request->description as $key=>$value){
$data[]=[
'description'=> $value,
'log_time'=> $request->log_time[$key],
'call_id'=>$call->id,
];
}
PortLog::create($data);
当我检查 dd($data)
array:2 [▼
0 => array:3 [▼
"description" => "des"
"log_time" => ""
"call_id" => 16
]
1 => array:3 [▼
"description" => ""
"log_time" => "hi"
"call_id" => 16
]
]
我做错了什么?
【问题讨论】:
-
错误告诉你。
preg_match()(在您的代码中的任何位置)没有被赋予正确的字符串参数。您的这部分代码没有我可以看到的preg_match(),因此此代码似乎与问题无关。 -
@Anant 不是它的错误非法字符串
-
是的,对不起,我当时正在删除我的评论,但由于网络问题,它没有被删除。
标签: php arrays laravel foreach