Code is not being read completely

1

In my Controller file, only the 'Return View' is being read, the next code goes straight through 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've divided:

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>
    
asked by anonymous 23.03.2017 / 13:20

1 answer

2

You have a return in the first line of the naocadastrado function:

return View('/naocadastrado');

All code after this line will not run. Here's what PHP's documentation says:

  

The return statement returns control of the program to the module that called it. The execution will continue in the expression following the invocation of the module.

     

If called within a function, the return statement will immediately terminate its execution, and return its arguments as value to the function call.

That is:

function a() {
    echo "Executou a função 'a'";
    b();
}

function b() {
    echo "A função 'a' executou a função 'b'";

    return;

    c();
}

function c() {
    echo "A função 'b' executou a função 'c'";
}

a();

We would have the following output:

  
  • You ran the 'a' function
  •   
  • Function 'a' has executed function 'b'
  •   

Notice that in the b function there is a return before calling the c function, so the c function will not be executed because the b function returned the control for the a function.

    
23.03.2017 / 13:32