Reputation: 73
This is what my code looks like
Route:
Route::put('/articles/{$article}', 'ArticlesController@update');
Controller:
public function update($id){
$article=Article::find($id);
$article ->title = request('title');
$article->excerpt=request('excerpt');
$article->body=request('body');
$article->save();
return redirect('/articles/'. $article->id);
}
Blade:
<form method="POST" action="/articles/{{$article->id}}" >
@csrf
@method('PUT')
And everytime I try to submit an update I get this:
The PATCH method is not supported for this route. Supported methods: GET, HEAD.
I'm currently stuck on this one.
Upvotes: 1
Views: 284
Reputation: 1045
simple way using blade
<form action="/articles/{{$article->id}}" method="POST">
@method('put')
@csrf
</form>
Upvotes: 1
Reputation: 420
It's better to do:
Route::put('/articles/{id}', 'ArticlesController@update')->name('articles.update');
public function update(Request $request, $id)
{
// logic
}
don't forget to use Request in controller
it's better to use naming for routes but it might be a problem in your action
<form method="POST" action="{{ route('articles.update', $article->id) }}">
Upvotes: 1
Reputation: 119
Try this
<form action="/articles/{{$article->id}}" method="POST">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
and the route
Route::put('/articles/{article}', 'ArticlesController@update');
Upvotes: 4