Hello, I am trying to enter data into two different tables through Laravel, the data comes from a view, the problem is that I get the following error
The GET method is not supported for this route. Supported methods: POST.
Apparently according to what I have asked it is due to the request but I am not sure, the first part that enters the data to the users table works correctly, apparently the problem comes in the if. Attached is the code of my controller:
public function RegistroCliente(Request $request)
{
$validacion = Validator::make($request->all(),
[
'usuario' => 'required|max:50',
'password' => 'required|min:6',
'rol'=>'required',
'cedula' => 'max:12',
'celular'=> 'max:10',
'ceco'=> '',
'direccion' =>'',
'lider' =>'',
'lab_usu_id'=>''
]);
if($validacion->fails())
{
return redirect('/registrar')
->withInput()
->withErrors($validacion);
}
$user=new tbl_usuario();
$user->usuario=$request->usuario;
$user->password=bcrypt($request->password);
$user->rol=$request->rol;
$user->cedula=$request->cedula;
$user->celular=$request->celular;
$user->save();
//$credentials =DB::select("SELECT max(rol) FROM tbl_usuario");
$credentials='Lab Catálisis';
if ($credentials=='Lab Catálisis') {
$lab=new tbl_lab();
$lab->ceco=$request->ceco;
$lab->direccion=$request->direccion;
$lab->lider=$request->lider;
$lab->lab_usu_id=DB::select("SELECT max(usu_id) FROM tbl_usuario");
$lab->save();
return view('login');
}
}
The view where I send the data is the following:
<form class="register-form" method="POST" action="{{ route('registro') }}" >
{{ csrf_field() }}
<div class="form-group">
<label>Usuario</label>
<input type="text" class="form-control" name="usuario" placeholder="Ingrese el usuario">
</div>
<div class="form-group">
<label>Contraseña</label>
<input type="password" name="password" class="form-control" placeholder="Ingrese la contraseña">
</div>
<div class="form-group">
<label for="exampleFormControlSelect1" onclick="comprobar()">Seleccione el Rol
<select class="form-control" id="rol" name="rol" required>
<option value="1" >----</option>
<option value="2">Lab Metrología</option>
<option value="3">Lab Suelos</option>
<option value="4">Lab Biotecnología</option>
<option value="5">Lab Análisis petrofísicos</option>
<option >Lab Catálisis</option>
</select>
</label>
<p id="datos" style="visibility: hidden;">
<label>
<label>CECO</label>
<input type="text" class="form-control" name="ceco" placeholder="Ingrese el codigo ceco">
<label>Direccion</label>
<input type="text" class="form-control" name="direccion" placeholder="Ingrese la dirección">
<label>Lider</label>
<input type="text" class="form-control" name="lider" placeholder="Ingrese el nombre del lider">
</label>
</p>
</div>
<div class="form-check">
<button type="submit" class="btn btn-register float-right">Registrar</button>
</div>
</form>
And the path is as follows:
Route::post('/registrar','registroController@RegistroCliente')->name('registro');
Thanks.
The only place where I see that there can be complications of this type is in the condition:
If I should roll back you should do something like this:
The error is because in your routing table (routes/web.php) the "register" route will be something like this:
And when redirecting to a route, it is usually done with get
I hope it works for you! ;)