当我尝试更新数据库中的记录时,它不会更新而且它
返回 false
。
我不明白要在
中传递什么作为图像位置$product->images()->update();
我不能使用 ids
作为搜索条件,我必须通过图像索引更新
。
<?php
if (isset($product->images[$key])) {
$result = $product->images[$key]->update([
'name' => $filename
]);
dd($result);
} else {
$product->images()->create([
'name' => $filename
]);
}
?>
最佳答案
也许您没有在 Images 模型的 $fillable
中将 name
字段定义为可批量分配。转到您的图像模型并定义此属性:
protected $fillable = ['name'];
关于php - Laravel 5 更新记录返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41604741/