gpt4 book ai didi

php - Laravel 6 : The GET method is not supported for this route. 支持的方法:POST 错误

转载 作者:行者123 更新时间:2023-12-04 10:39:55 25 4
gpt4 key购买 nike

我是 Laravel 6 的新手,我正在尝试创建编辑配置文件功能,但我遇到了错误:

The GET method is not supported for this route. Supported methods: POST

老实说,我不确定为什么会出现此错误。我已经交叉检查了一切。

配置文件 Controller
更新功能
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');

编辑 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 提供使用 5 种方法。

GET/contacts, mapped to the index() method and shows contacts list,
GET /contacts/create, mapped to the create() method and shows create form,
POST /contacts, mapped to the store() method and handle create form request,
GET /contacts/{contact}, mapped to the show() method and shows single item,
GET /contacts/{contact}/edit, mapped to the edit() method and shows update form,
PUT/PATCH /contacts/{contact}, mapped to the update() method and handle update form request,
DELETE /contacts/{contact}, mapped to the destroy() method and handle delete form request.

你必须改变你的 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/

关于php - Laravel 6 : The GET method is not supported for this route. 支持的方法:POST 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59978514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com