此查询仅向DB插入一条记录,我该怎么做才能插入多条记录?
sample_music::create(
array(
'artist'=> \Input::input('artist')
));
答案 0 :(得分:0)
假设你有如下的json列表,
$str = '{
"artist": [
"x",
"y",
"z"
]
}';
$x = json_decode($str);
$artistArr = array();
foreach($x->artist as $artist)
$artistArr[] = array("artist" => $artist);
sample_music::insert($artistArr);
这样做