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

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

我正在尝试将一个简单的示例作为一个表单请求,但我卡在下面是我的简单代码

这是 register.blade.php 文件:

<html>

   <head>
      <title>Form Example</title>
   </head>

   <body>
    <form action = "/user/register" method = "post">
        @csrf
         <table>
            <tr>
               <td>Name</td>
               <td><input type = "text" name = "name" /></td>
            </tr>
            <tr>
               <td>Username</td>
               <td><input type = "text" name = "username" /></td>
            </tr>
            <tr>
               <td>Password</td>
               <td><input type = "text" name = "password" /></td>
            </tr>
            <tr>
               <td colspan = "2" align = "center">
                  <input type = "submit" value = "Register" />
               </td>
            </tr>
         </table>

      </form>
   </body>
</html>

这里是控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    public function init($id)
    {
        echo "<br>Test Controller." . $id;
    }
    public function showProfile()
    {
        echo "<br>showProfile.";
    }
    public function postRegister(Request $request)
    {
      //Retrieve the name input field
      $name = $request->input('name');
      echo 'Name: '.$name;
      echo '<br>';

      //Retrieve the username input field
      $username = $request->username;
      echo 'Username: '.$username;
      echo '<br>';

      //Retrieve the password input field
      $password = $request->password;
      echo 'Password: '.$password;
    }
}

这是路由文件

Route::get('/register', function () {
    return view('register');
});
Route::post('/user/register', [TestController::class, 'showProfile']);

我编码的错误是这个

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The POST method is not supported for this route. Supported methods: GET, HEAD.

我想念什么??我认为问题太简单了,但我找不到它可能问题是寄存器视图文件是一个 blade 文件而不是单个 php

php artisan route:clear

解决了我的问题感谢@sta 的观察