简体   繁体   English

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

[英]Laravel 6: The GET method is not supported for this route. Supported methods: POST Error

I'm new to Laravel 6, and I'm trying to make a edit profile feature but I'm stuck with the error:我是 Laravel 6 的新手,我正在尝试制作一个编辑配置文件功能,但我遇到了错误:

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

To be honest, I am not sure why i get this error.老实说,我不确定为什么会收到此错误。 I have cross checked everything.我已经交叉检查了所有内容。

ProfileController update function 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');
    }

My route file:我的路线文件:

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

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

edit.blade.php编辑刀片.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>
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
}

As a usal Laravel offers using 5 methods.通常,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.

You have to change your route.php file您必须更改您的 route.php 文件

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

And in your form, change action并以你的形式,改变行动

<form action="{{ route('profile.update', Auth::user()->id) }}" method="POST">
...
</form>

For more: https://www.techiediaries.com/php-laravel-crud-mysql-tutorial/更多信息: https ://www.techiediaries.com/php-laravel-crud-mysql-tutorial/

in your edit.blade.php file remove在您的 edit.blade.php 文件中删除

 @method('PUT')

then your method will be post only那么您的方法将仅发布

You can set route method any您可以设置任何路由方法

Change Route::post('/profile/edit','ProfileController@update')->name('profile.update'); 
to 
Route::any('/profile/edit','ProfileController@update')->name('profile.update'); change 

Thanks谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel: MethodNotAllowedHttpException: 此路由不支持 GET 方法。 支持的方法:POST - Laravel: MethodNotAllowedHttpException: The GET method is not supported for this route. Supported methods: POST Laravel - 此路由不支持 POST 方法。 支持的方法:GET、HEAD - Laravel - The POST method is not supported for this route. Supported methods: GET, HEAD 此路由不支持 GET 方法。 支持的方法:POST。 与 laravel - The GET method is not supported for this route. Supported methods: POST. with laravel Laravel 8:此路由不支持 GET 方法。 支持的方法:POST - Laravel 8: The GET method is not supported for this route. Supported methods: POST 此路由不支持 GET 方法。 支持的方法:POST Laravel 8 - The GET method is not supported for this route. Supported methods: POST Laravel 8 此路由不支持 GET 方法。 支持的方法:POST。 在 laravel 8 - The GET method is not supported for this route. Supported methods: POST. in laravel 8 此路由不支持 POST 方法。 支持的方法:GET、HEAD (LARAVEL) - POST method is not supported for this route. Supported methods: GET, HEAD (LARAVEL) 此路由不支持 GET 方法。 支持的方法:POST。 拉拉维尔 8 - The GET method is not supported for this route. Supported methods: POST. laravel 8 Laravel此路由不支持GET方法。 支持的方法:POST - Laravel The GET method is not supported for this route. Supported methods: POST 此路由不支持 POST 方法。 支持的方法:GET、HEAD In Laravel - The POST method is not supported for this route. Supported methods: GET, HEAD In Laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM