Php 此路由不支持GET方法

Php 此路由不支持GET方法,php,laravel,laravel-8,Php,Laravel,Laravel 8,我正在与Laravel 8合作开发我的项目,我已经创建了此表单用于验证令牌: <div class="card-body"> <form action="{{ route('profile.2fa.phone') }}" method="POST"> @csrf <div class="form-group"> &l

我正在与Laravel 8合作开发我的项目,我已经创建了此表单用于验证令牌:

<div class="card-body">
    <form action="{{ route('profile.2fa.phone') }}" method="POST">
        @csrf

        <div class="form-group">
            <label for="token" class="col-form-label">Token</label>
            <input type="text" class="form-control @error('token') is-invalid @enderror" name="token" placeholder="enter your token">
            @error('token')
                <span class="invalid-feedback">
                <strong>{{ $message }}</strong>
            </span>
            @enderror
        </div>
        <div class="form-group">
            <button class="btn btn-primary">Validate token</button>
        </div>
    </form>
</div>
但是现在,当我添加令牌并按下Validate token(验证令牌)按钮时,我得到以下错误:

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException 此路由不支持GET方法。支持的方法: 邮局

那么这里出了什么问题?我如何解决这个问题

我非常感谢你们的任何想法或建议


提前感谢。

首先,您需要检查是否正在创建路由。 执行:php artisan路由:列表。 如果与POST无关,请执行以下命令:

php artisan配置:缓存//清除配置缓存 php artisan配置:清除//清除配置缓存 php artisan缓存:清除//清除缓存 php artisan optimize//重新优化类装入器 php artisan路由:缓存//清除路由缓存 php artisan视图:清除//清除视图缓存 以一种简单的方式-php artisan优化

如果这并没有帮助确保您的路线是您正在搜索的路线

UDP:name方法未按您希望的方式工作。尝试在不使用此方法的情况下声明名称

如果需要,可以尝试使用以下路由格式:
路由::匹配['get','post']

首先,您需要检查是否正在创建路由。 执行:php artisan路由:列表。 如果与POST无关,请执行以下命令:

php artisan配置:缓存//清除配置缓存 php artisan配置:清除//清除配置缓存 php artisan缓存:清除//清除缓存 php artisan optimize//重新优化类装入器 php artisan路由:缓存//清除路由缓存 php artisan视图:清除//清除视图缓存 以一种简单的方式-php artisan优化

如果这并没有帮助确保您的路线是您正在搜索的路线

UDP:name方法未按您希望的方式工作。尝试在不使用此方法的情况下声明名称

如果需要,可以尝试使用以下路由格式:
路由::匹配['get','post']

Laravel将按照声明的顺序匹配路由

要解决问题,您需要在Route::get之前声明Route::post


GET请求应始终声明为路由列表中的最后一个方法,因为它将使用MethodNotAllowedHttpException捕获任何其他请求。

Laravel将按照声明的顺序匹配路由

要解决问题,您需要在Route::get之前声明Route::post


GET请求应始终声明为路由列表中的最后一个方法,因为它将使用MethodNotAllowedHttpException捕获任何其他请求。

我对此进行了测试,但仍然出现错误:此路由不支持GET方法。支持的方法:POST。你能写一个使用Route::match的例子吗?是的,这里是:Route::match[],[Someclass::class,'SomeU方法\U of the_class']->methods;针对您的情况:Route::match['get','post'],'/settings/twofactor/phone',[App\Http\Controllers\Admin\AdminSettingsController::class','postPhoneVerify','getPhoneVerify'];那么我应该在它的末尾添加->name'profile.2fa.phone'还是仅仅添加/settings/twofactor/phone uri作为表单操作?我对此进行了测试,但仍然出现错误:此路由不支持GET方法。支持的方法:POST。你能写一个使用Route::match的例子吗?是的,这里是:Route::match[],[Someclass::class,'SomeU方法\U of the_class']->methods;针对您的情况:Route::match['get','post'],'/settings/twofactor/phone',[App\Http\Controllers\Admin\AdminSettingsController::class','postPhoneVerify','getPhoneVerify'];那么我应该在它的末尾添加->name'profile.2fa.phone'还是仅仅添加/settings/twofactor/phone uri作为表单操作?尝试更改尝试更改
Route::get('/settings/twofactor/phone' , [App\Http\Controllers\Admin\AdminSettingsController::class, 'getPhoneVerify']);

Route::post('/settings/twofactor/phone' , [App\Http\Controllers\Admin\AdminSettingsController::class, 'postPhoneVerify'])->name('profile.2fa.phone');