I have the authenticate function that verifies that the email and password entered match those of the users table. The code is working, but after verifying that email and password check, I redirect to the logged in view. So far so good. But I wish this view would not be accessed directly. I would like to make it accessible only to those who are logged in. Did you understand? Because if I access the direct url of this view, it accesses. I want to restrict this.
public function autenticar(Request $request)
{
//Pego dados do formulário de login e armazeno na variavel $dados
$dados = $request->except('_token');
//Depois de armazenar na variavel dados, separo em $email e $password
$email = $dados['email'];
$password = $dados['password'];
//Faz a consulta e verifica se email digitado é igual email do banco
$query = $this->user->where('email', $email)->first();
//Verifica se o email existe
if (!$query)
{
return null;
}
//Verifica se a senha digitada é igual a senha hash do banco
if (Hash::check($password, $query->password))
{
return redirect()->route('logado');
}
else
{
return null;
}