i am trying to make working a simple example a form request but I am stuck below is my simple code
Here is the register.blade.php file:
JavaScript
x
<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>
here is the controller:
JavaScript
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
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;
}
}
here is the route files
JavaScript
Route::get('/register', function () {
return view('register');
});
Route::post('/user/register', [TestController::class, 'showProfile']);
the error that i code is this
JavaScript
SymfonyComponentHttpKernelExceptionMethodNotAllowedHttpException
The POST method is not supported for this route. Supported methods: GET, HEAD.
what i miss?? i think the problem its too simple but i cant find it maybe the problem is that the register view file is a blade file and not a single php
Advertisement
Answer
JavaScript
php artisan route:clear
solve my problem thnx to @sta for this observation