【发布时间】:2023-03-31 13:02:01
【问题描述】:
我一直在 laravel 的一个学校项目上工作,我希望能够更新我数据库中的现有记录,我已经为它做了一个功能,但是当我点击更新按钮时,只有 Updated_at 字段我的数据库已更新,没有其他内容,即使我更改了编辑表单上的每个属性,我也观看并关注了 Laracasts laravel 基础系列,但它给了我相同的结果。
这是我为它制作的商店和编辑方法
public function update(Request $request, $id)
{
//$product = Product::findOrFail($id) = finding the Id of the Product i want to update
$product = Product::FindorFail($id);
// Requesting a update query on the attributes: name , buy price, sell price, and the foreign_key
$product->update($request->only(['naam', 'inkoopPrijs', 'verkoopPrijs', 'Fabrieken_Id']));
return redirect(Route('producten.index'));
}
这是我正在使用的模型。
class Product extends Model
{
protected $fillable = ['Id', 'naam', 'inkoopPrijs', 'verkoopPrijs', 'Fabrieken_Id', 'updated_at', 'created_at'];
protected $table = "producten";
public function fabriek()
{
return $this->BelongsTo('App\Fabriek', 'Fabrieken_Id');
}
当我像上面所说的那样 var_dump($product) 只更新 Updated_at 字段时,没有别的。
如果我需要更多信息,请告诉我,我会将其添加到问题中
【问题讨论】:
标签: laravel laravel-5.2