1
In my Controller file, only the 'Return View' is being read, the following code is passed directly and ends.
public function naocadastrado()
{
return View('/naocadastrado');
$user = new \App\User();
$user->Name = Input::get('Name');
$user->User = Input::get('User');
$user->Password = hash('sha256', Input::get('Password'));
$user->Tipo = Input::get('tipo_usuario');
if("SELECT COUNT(*) AS total FROM tabela WHERE campo='User'"){
return redirect('/cadastroexistente');
}else{
return redirect('/cadastrado');
}
$user->save();
}
public function naocadastrado()
{
return View('/naocadastrado');
}
public function ncadastrado()
{
$user = new \App\User();
$user->Name = Input::get('Name');
$user->User = Input::get('User');
$user->Password = hash('sha256', Input::get('Password'));
$user->Tipo = Input::get('tipo_usuario');
if("SELECT COUNT(*) AS total FROM tabela WHERE campo='User'"){
return redirect('/cadastroexistente');
}else{
return redirect('/cadastrado');
}
$user->save();
}
I shared:
WEB.PHP
Route::group (['prefix' => '', 'namespace' => 'Api'], function(){
Route::get('/naocadastrado', 'CadastroController@naocadastrado');
Route::post('/naocadastrado', 'CadastroController@ncadastrado');
});
BLADE
<body>
<form method="POST" action="/ncadastrado">
<h1> Cadastro de Usuários UNIUS <br> </h1>
<h2> USUÁRIO NÃO CADASTRADO<br> CADASTRE-SE! </h2>
<label><b>Nome:</label> <input type="text" name="Name"> <br>
<label><b>E-mail:</label> <input type="text" name="User"> <br>
<label>Senha:</label> <input type="password" name="Password" > <br>
<label>Tipo de usuário</label>
<select name="tipo_usuario">
<option value="">Selecione</option>
<option value="Administrador">Administrador</option>
<option value="Desenvolvedor">Desenvolvedor</option>
</select><br><br>
<input type="submit" value="Cadastrar" id="cadastrar" name="cadastrar">
</form>
</body>
you are checking a string with something in if logo is always true.There is something missing.
– rray
will not continue anything even, right in the first line of the method already has the Return, after that you can put whatever you want it will never run.
– Marcelo Diniz
Got it! Thank you xD
– Vitória
Why do you want to change the first line? As Marcelodiniz the remaining code will not be executed. And in the IF part, do the command to execute the query before and then compare to see if you returned any record, type rowCount or checking if it is true to run the block.
– Jeferson Leonardo