Laravel 中的 Update() 似乎无法正常工作

Update() in Laravel does not seem to be working

我正在与 Laravel 5.8 合作开发我的项目,我有这个 table,它显示了数据库中的一些数据:

@foreach(\App\Shop\ProductDelivery::all() as $delivery)
<tr>
    <td>{{ $delivery->name }}</td>
    <td>{{ $delivery->price }}</td>
    <td>
        <a href="{{ route('editFreeDelivery', $delivery->id) }}">Edit</a>
    </td>
</tr>
@endforeach

如您所见,有一个名为 Edit 的 link 用于编辑这些数据,因此当有人单击它时,此方法将运行:

Route::get('product-information-pages/free-deliveries/{productDelivery}/edit', 'ShopInformationPagesAdminController@editFreeDelivery')->name('editFreeDelivery')->middleware('permission:static-page-manage');

public function editFreeDelivery(ProductDelivery $productDelivery)
    {
        return view('admin.shop.deliveries.edit', compact('productDelivery'));
    }

我还添加了此表单以更新发送到 edit.blade.php:

的数据
<form action="{{ route('updateProductDelivery', [$productDelivery->id]) }}" method="POST" enctype="multipart/form-data">
    @csrf
    {{  @method_field('PATCH') }}
    <label for="title" class="control-label">Name</label>
    <input type="text" id="title-shop" name="name" disabled="disabled" class="form-control" value="{{ old('name' , $productDelivery->name) }}" autofocus>
    <label for="price" class="control-label">Price</label>
    <input type="text" id="price_shop" name="price" class="form-control" value="{{ old('price' , $productDelivery->price) }}" autofocus>
    <button class="btn btn-success" type="submit">Submit</button>
</form>

这里是更新数据的方法:

Route::patch('product-information-pages/free-deliveries/{productDelivery}', 'ShopInformationPagesAdminController@updateProductDelivery')->name('updateProductDelivery')->middleware('permission:static-page-manage');

public function updateProductDelivery(Request $request, ProductDelivery $productDelivery)
    {
        try {
            $data = $request->validate([
                'name' => ['required'],
                'price' => ['required','integer'],
            ]);
            $productDelivery->update($data);
        } catch (\Exception $e) {
            dd($e);
        }
        return redirect(route('product-information-pages.create'));
    }

但现在的问题是,数据不会以某种方式更改和更新,并显示为 dd($e):

那么这里出了什么问题?我该如何解决这个问题?

最后是模型 ProductDelivery.php:

class ProductDelivery extends Model
{
    protected $table = "product_deliveries";
}

而 table product_deliveries 看起来像这样:

更新 #1:

dd($productDelivery->toArray()); 的结果是这样的:

array:5 [▼
  "id" => 1
  "name" => "Free Delivery"
  "price" => 300000
  "created_at" => "2021-07-04 14:16:09"
  "updated_at" => "2021-07-04 14:16:09"
]

你有一个

 $productDelivery->update($data);

但是,你说怎么对你的产品更新什么功能?你首先需要像

这样的东西
$productDelivery = productDelivery::find($id)
$productDelivery->update($data);

您的输入已被禁用,禁用字段未随请求一起提交。

<input type="text" id="title-shop" name="name" class="form-control" value="{{ old('name' , $productDelivery->name) }}" autofocus>

尝试使用 readonly="readonly" 而不是禁用,或者如果不应更改该字段,则从请求中完全省略该字段。