我最近加入了Laravel框架,所以首先我試圖在laravel中創建一個CRUD系統,以瞭解他們的基本功能。MethodNotAllowedHttpException while laravel更新記錄
現在在這裏,我在更新現有記錄的時間面對錯誤MethodNotAllowedHttpException。
在這裏,在我的路線
Route::resource('product', 'ProductController');
這給了我可能的路線
| GET|HEAD | product | product.index | App\Http\Controllers\[email protected]
| POST | product | product.store | App\Http\Controllers\[email protected]
| GET|HEAD | product/create | product.create | App\Http\Controllers\[email protected]
| GET|HEAD | product/{product} | product.show | App\Http\Controllers\[email protected]
| DELETE | product/{product} | product.destroy | App\Http\Controllers\[email protected]
| PUT|PATCH | product/{product} | product.update | App\Http\Controllers\[email protected]
| GET|HEAD | product/{product}/edit | product.edit | App\Http\Controllers\[email protected]
Editform視圖
@extends('layouts.app')
@section('title','Product List')
@section('content')
<div class="container">
<form action="{{url('product/'.$product['id'])}}" class="form-horizontal">
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
{{csrf_field()}}
{{ method_field('PUT')}}
<!-- <input name="_method" type="hidden" value="PUT"> -->
<input type="text" name="name" class="form-control" id="exampleInputEmail1" value="{{$product['name']}}" aria-describedby="emailHelp" placeholder="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">category</label>
<input type="text" value="{{$product['category']}}" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" name="category" placeholder="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">weight</label>
<input type="text" value="{{$product['weight']}}" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" name="weight" placeholder="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">price</label>
<input type="text" value="{{$product['price']}}" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" name="price" placeholder="">
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>
</div>
@endsection
以下列表10
ProductController.php
public function update(Request $request, $product_id)
{
$created = product::create($request->all());
if($created){
return redirect('product')->with('message','data added');
}
}
在這種情況下,每當我婉refiling編輯的形式來改變現有的記錄數據。它會生成MethodNotAllowedHttpException錯誤。
我嘗試了很多解決方案,但沒有修復。所以請指導我出錯的地方。謝謝
好的,補充。但它沒有迴應。我的網址欄填入他們已更改的數據..! –
顯示完整的表格 –
對不起,您需要填寫哪種表格? –