-1
Good morning, I’m making a little project with Laravel
, I’m at the authentication part and I had a question. i protected a group of routes with middleware auth so the user will only be able to access the route home if it authenticates first, but here comes the problem I can’t access this route within the auth with a route from outside of this group so it’s not directing to it so how will I access it? below the code:
View login
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="{{asset('css/style.css')}}">
<link rel="stylesheet" href="{{asset('css/style-form.css')}}">
<script src="{{asset('jquery/jquery.js')}}"></script>
<script src="{{asset('bootstrap/js/bootstrap.js')}}"></script>
</head>
<body class="bg-dark">
<div class="container col-lg-4">
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="card ml-auto mr-auto">
<div class="card-header">
<h5>Login</h5>
</div>
<div class="card-body">
<form action="{{route('entrar')}}" class="form-horizontal" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
@csrf
<div class="form-group">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><img src="{{asset('img/user-solid.svg')}}" width="20px" height="20px"></span>
</div>
<input type="text" class="form-control form-control-lg" name="email" placeholder="[email protected]" aria-label="Usuário" aria-describedby="basic-addon1">
</div>
</div>
<div class="form-group">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><img src="{{asset('img/key-solid.svg')}}" width="20px" height="20px"></span>
</div>
<input type="password" name="password" id="senha" class="form-control form-control-lg" placeholder="***********" aria-label="Usuário" aria-describedby="basic-addon1">
</div>
<select class="form-control" name="cargo">
<option>Gerente</option>
<option>Funcionario</option>
</select>
</div>
<button type="submit" class="btn btn-primary btn-block">Entrar</button>
</form>
</div>
</div>
</div>
</body>
</html>
Routes
Route::get('/', function () {
return view('logar.login');
})->name('login');
Route::post('/login/entrar',['uses'=>'LoginController@entrar'])->name('entrar');
//Route::get('/teste',['uses'=>'LoginController@teste'])->name('teste');
Route::group(['middleware'=>'auth'],function(){
Route::get('/home',['uses'=>'LoginController@entrar'])->name('home');
Route::get('/logout',['uses'=>'LoginController@logout'])->name('logout');
Route::get('/funcionario',['uses'=>'FuncionarioController@visualizar'])->name('funcionarioVisualizar');
Route::get('/funcionario/adicionar',['uses'=>'FuncionarioController@adicionarFuncionario'])->name('adicionarFuncionario');
Route::get('/produto',['uses'=>'ProdutoController@index'])->name('produto');
Route::get('/produto/adicionar',['uses'=>'ProdutoController@adicionarProduto'])->name('adicionarProduto');
});
Login controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
public function entrar(Request $req)
{
$dados = $req->all();
if (Auth::attempt(['email'=>$dados['email'],'password'=>$dados['password']])) {
return redirect()->route('home');
} else {
return redirect()->route('login');
}
}
public function logout()
{
Auth::logout();
}
}
was that right vlw
– Adriano Rufino