首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel 6:此路由不支持GET方法。支持的方法: POST错误

Laravel 6:此路由不支持GET方法。支持的方法: POST错误
EN

Stack Overflow用户
提问于 2020-01-30 11:01:45
回答 4查看 3.7K关注 0票数 2

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

代码语言:javascript
复制
The GET method is not supported for this route. Supported methods: POST

老实说,我不确定为什么会出现这个错误。我已经交叉检查过所有东西了。

ProfileController更新函数

代码语言:javascript
复制
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');
    }

我的路由文件:

代码语言:javascript
复制
Route::get('/profile', 'ProfileController@index')->name('profile');

Route::put('/profile/edit/{profile}','ProfileController@update')->name('profile.update');

edit.blade.php

代码语言:javascript
复制
<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>
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2020-01-30 16:41:23

作为一个推论,Laravel提供了使用5种方法。

代码语言:javascript
复制
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文件

代码语言:javascript
复制
Route::put('/profile/edit/{profile}','ProfileController@update')->name('profile.update');

在您的表单中,更改操作

代码语言:javascript
复制
<form action="{{ route('profile.update', Auth::user()->id) }}" method="POST">
...
</form>

有关更多信息,请访问:https://www.techiediaries.com/php-laravel-crud-mysql-tutorial/

票数 1
EN

Stack Overflow用户

发布于 2020-01-30 16:40:23

代码语言:javascript
复制
You are getting the error because your route expects post and you are using get method

Route::get('/profile/edit','ProfileController@edit')->name('profile.edit');


Route::put('/profile/','ProfileController@update')->name('profile.update');


public function edit() {

return view (edit);
}

public function update() {

//things to update
}
票数 1
EN

Stack Overflow用户

发布于 2020-01-30 16:00:57

在edit.blade.php文件中删除

代码语言:javascript
复制
 @method('PUT')

则您的方法将仅为post

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59978514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档