我想使用此字段,我想在此description []中插入description1,description2数据[]我尝试过的操作,但是缺少一些东西。
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description[]" placeholder="Enter description">
</div>
</div>
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description 1 (optional)</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description2" placeholder="Enter description">
</div>
</div>
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description 2 (optional)</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description3" placeholder="Enter description">
</div>
</div>
public function store(Request $request)
{
$description1 = $request->input('description1');
$description2 = $request->input('description2');
$products = new ProductAdd;
$prodduct->name = $request('name');
$prodduct->description[] = [
'description1' => $description1;
'description2' => $description2;
];
$product->save();
}
答案 0 :(得分:0)
如果将description
字段强制转换为模型中的数组,则可以将控制器代码更新为:
$prodduct->description = [
'description1' => $description1;
'description2' => $description2;
];
要将字段转换为数组,请将其添加到您的ProductAdd
模型中:
$casts = [
'description' => 'array'
];