I've recently joined Laravel framework so firstly i trying to make a CRUD system in laravel, for understanding their fundamentals their functionality.
Now here i've face a error MethodNotAllowedHttpException at the time of updating existing record.
Here in my routes
Route::resource('product', 'ProductController');
Which gives me the following list of possible routes
| GET|HEAD | product | product.index | App\Http\Controllers\ProductController@index
| POST | product | product.store | App\Http\Controllers\ProductController@store
| GET|HEAD | product/create | product.create | App\Http\Controllers\ProductController@create
| GET|HEAD | product/{product} | product.show | App\Http\Controllers\ProductController@show
| DELETE | product/{product} | product.destroy | App\Http\Controllers\ProductController@destroy
| PUT|PATCH | product/{product} | product.update | App\Http\Controllers\ProductController@update
| GET|HEAD | product/{product}/edit | product.edit | App\Http\Controllers\ProductController@edit
Editform view
@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
ProductController.php
public function update(Request $request, $product_id)
{
$created = product::create($request->all());
if($created){
return redirect('product')->with('message','data added');
}
}
In this situation, whenever i wan to change existing records data by refiling edit form. it generates MethodNotAllowedHttpException error.
i tried lots of solutions but it not fixed. So please guide where i am going wrong. Thanks