我是Laravel 6的新手,我正在尝试制作编辑配置文件功能,但由于错误而被卡住:
The GET method is not supported for this route. Supported methods: POST
老实说,我不确定为什么会收到此错误。交叉检查了4小时。
ProfileController更新功能
public function update(Request $request, $id)
{
$profile->nickname = $request->input('nickname');
$profile->name = $request->input('name');
$profile->birthday = $request->input('birthday');
$profile->save(); //persist the data
return redirect()->route('profile.index')->with('info','Profile got saved');
}
我的路线文件:
Route::post('/profile/edit','ProfileController@update')->name('profile.update');
edit.blade.php
<form action="{{route('profile.update')}}" method="POST">
@csrf
@method('PUT')
<div class="form-group row">
<label for="nickname" class="col-md-4 col-form-label text-md-right">{{ __('Brugernavn') }}</label>
<div class="col-md-6">
<input id="nickname" type="text" class="form-control @error('nickname') is-invalid @enderror" name="nickname" value="{{ Auth::user()->nickname }}">
</div>
</div>
<!-- Submit -->
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-secondary">
Gem
</button>
</div>
</div>
</form>
您必须更改route.php文件
Route::put('/profile/edit/{profile}','ProfileController@update')->name('profile.update');
然后以您的形式,更改操作
<form action="{{ route('profile.update', Auth::user()->id) }}" method="POST">
...
</form>
有关更多:https://www.techiediaries.com/php-laravel-crud-mysql-tutorial/
在您的edit.blade.php文件中删除
@method('PUT')
然后您的方法将只能发布
您可以设置任何路线方法
Change Route::post('/profile/edit','ProfileController@update')->name('profile.update');
to
Route::any('/profile/edit','ProfileController@update')->name('profile.update'); change
谢谢
您收到错误,因为您的路线需要发布并且您正在使用get方法
Route :: get('/ profile / edit','ProfileController @ edit')-> name('profile.edit');
Route :: put('/ profile /','ProfileController @ update')-> name('profile.update');
公共功能edit(){
返回视图(编辑);}
public function update(){
//要更新的内容}