2 回答
TA贡献1859条经验 获得超6个赞
看起来你的$request->input('characteristic');是一个数组而不是字符串。
你需要一个循环来解决这个问题。一种方法可以是:
$data = []
foreach ($request->input('characteristic') as $characteristic) {
$data[] = [
'characteristic' => $characteristic,
'property_id' => '' // something
];
}
Characteristic::insert($data);
->saveMany()更好的方法是通过设置关系来使用hasMany()。
$characteristics = [];
foreach ($request->input('characteristic') as $characteristic) {
$characteristics = new Characteristic([
'characteristic' => $characteristic
]);
}
$property->characteristics()->saveMany($characteristics);
TA贡献1784条经验 获得超9个赞
我能够保存数据如下
$piso_id = $properti->id;
foreach ($request->input('characteristic') as $characteristic) {
$charc = new Characteristic;
$charc->property_id = $piso_id;
$charc->characteristic = $characteristic;
$charc->save();
}
- 2 回答
- 0 关注
- 117 浏览
添加回答
举报