【问题标题】:Laravel update record with PassportLaravel 使用 Passport 更新记录
【发布时间】:2019-05-26 14:55:09
【问题描述】:

大家好,今天我的 api 有这个问题。 我不更新数据库上的记录。 在邮递员中,响应是正确的,但不要保存在数据库中。 在 Postaman 中,我使用 PUT 方法传递并在正文名称中设置文本

产品控制器:

public function update(Request $request, $id)
{
    $product = auth()->user()->products()->find($id);

    if (!$product) {
        return response()->json([
            'success' => false,
            'message' => 'Product with id ' . $id . ' not found'
        ], 400);
    }

    $updated = $product->fill($request->all())->save();

    if ($updated)
        return response()->json([
            'success' => true
        ]);
    else
        return response()->json([
            'success' => false,
            'message' => 'Product could not be updated'
        ], 500);
}

【问题讨论】:

    标签: api laravel-5 token updates


    【解决方案1】:

    您应该查看您的 Product 模型以查看名称是否设置为可填写字段:$fillable = ['name'];。此外,密钥可能只是name 而不是"name"

    【讨论】:

      猜你喜欢
      • 2017-06-24
      • 1970-01-01
      • 2023-03-28
      • 2012-11-21
      • 1970-01-01
      • 1970-01-01
      • 2019-03-04
      • 1970-01-01
      • 2020-11-13
      相关资源
      最近更新 更多