【发布时间】:2020-05-15 15:00:29
【问题描述】:
我是 Laravel 6 的新手,我正在尝试创建一个编辑配置文件功能,但我遇到了错误:
The GET method is not supported for this route. Supported methods: POST
老实说,我不确定为什么会出现此错误。我已经交叉检查了所有内容。
配置文件控制器 更新函数
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::get('/profile', 'ProfileController@index')->name('profile');
Route::put('/profile/edit/{profile}','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>
【问题讨论】:
-
你添加了欺骗表单方法,但是 Laravel 没有运行
put动作。你应该执行php artisan route:list来检查第一个匹配的规则。 -
您的路线不正确,您的路线定位错误。检查您的路线,要进行编辑,您必须传递一个 id,但对于更新,您还必须传递数据和 id,如果您使用过
PUT,那么您的路线方法也将是PUT,如果它是 @987654329 @方法在你的路由中,那么你不需要在你的表单中使用PUT方法。 -
只是出于好奇:
Route::post不是很清楚吗? ;)