Reputation: 1
Iam trying to update a specific data using post method. After submitting the form it shows an error : The POST method is not supported for this route. Supported methods: GET, HEAD.
editpage.blade.php
@extends('layouts.app')
@section('content')
<div class="container">
<h3>Update Book</h3>
<br>
<form action="update" method="post" >
{{csrf_field()}}
@foreach($array as $fetch)
<div><input type="hidden" name="id" value="{{$fetch->id}}"></div>
<div><input type="text" name="name" class="form-control " placeholder="Bookname" value="{{$fetch->name}}" ></div><br>
<div><textarea name="content" class="form-control" rows="5" placeholder="Description" >{{$fetch->content}}</textarea></div><br>
<div><input type="text" name="author" class="form-control" placeholder="Author" value="{{$fetch->author}}"></div> <br>
<div><input type="submit" name="submit" value="Update Book" class="btn btn-success" ></div>
@endforeach
</form>
</div>
@endsection
Web Route
Route::get('/', function () {
return view('welcome');
});
Route::get('/addbook',function () {
return view('AddBook');
});
Route::post('/insert',['uses'=>'BookController@insert']);
Route::get('/delete/{id}',['uses'=>'BookController@delete']);
Route::get('/edit/{id}',['uses'=>'BookController@edit']);
``````
Route::post('/update',['uses'=>'BookController@update']);
```````
Route::get('/home',['uses'=>'BookController@index']);
Auth::routes();
Upvotes: 0
Views: 1004
Reputation: 1050
There are action like update which requires the method submitted to the server url to be either PUT/PATCH (to modify the resource)
Try with this,
<form action="{{ route('book.update') }}" method="post" >
{{csrf_field()}}
{{ method_field('PUT') }}
@foreach($array as $fetch)
// ...
@endforeach
</form>
Your Route,
Route::put('update',['uses'=>'BookController@update', 'as' => 'book.update']);
Your Controller
public function update(Request $request)
{
// ...
}
Hope this helps :)
Upvotes: 1