Hello, I find myself making a record in Laravel but when I click on a button to open the record view, I get the following error:
The GET method is not supported for this route. Supported methods: POST.
The view code is as follows:
<form class="register-form" action="{{ url('/registrar') }}" method="POST">
{{ csrf_field() }}
<div class="form-group">
<label for="exampleInputUsername" class="text-uppercase">Usuario</label>
<input type="text" class="form-control" name="usuario" placeholder="Ingrese el usuario">
<div class="form-group">
<label for="exampleInputPassword1" class="text-uppercase">Contraseña</label>
<input type="password" name="password" class="form-control" placeholder="Ingrese la contraseña">
</div>
<div class="form-check">
<button type="submit" class="btn btn-register float-right">Registrar</button>
</div>
</form>
I have the route in the web.php like this
Route::post('/registrar','registroController@RegistroCliente')->name('registro');
And the code in my controller is as follows:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\tbl_usuario;
class loginController extends Controller
{
public function RegistroCliente(Request $request)
{
$validacion = Validator::make($request->all(),
[
'usuario' => 'required|max:50',
'password' => 'required|min:6'
]);
if($validacion->fails())
{
return redirect('/#register')
->withInput()
->withErrors($validacion);
}
$user=new tbl_usuario();
$user->usuario=$request->usuario;
$user->password=$request->password;
}
}
The solution to the error was the following, in my routes I was calling the controller directly from the login button, so that was generating an error for me, the solution was to create a route and press the button to redirect me to that route:
And after the form put the action to the following route that goes to the controller
Thanks for the help.