0
Personal I’m with login error in Laravel:
Autenticacaocontroller.php
public function logar(Request $request){
$dados = $request->all();
$cpf = $dados['cpf'];
$senha = $dados['senha'];
$usuario = Usuario::where('cpf', $cpf)->first();
if (Auth::check() || ($usuario && Hash::check($senha, $usuario->senha))){
Auth::login($usuario);
return view('municipios.index');
}else{
return view('autenticacao.login');
}
}
web php.
Route::post('/logar', 'AutenticacaoController@login')->name('autenticacao.logar');
Login Form
<form action="{{route('autenticacao.logar')}}" method="post">
{{csrf_field()}}
<input type="text" name="cpf" class="form-control" placeholder="CPF" />
<br/>
<input type="password" name="senha" class="form-control" placeholder="senha" />
<br/>
<button type="submit" class="btn btn-primary btn-block btn-flat">Entrar</button>
</form>
Auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'usuarios',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'usuarios' => [
'driver' => 'eloquent',
'model' => App\Usuario::class,
],
User.php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Usuario extends Authenticatable
{
use Notifiable;
protected $fillable = [
"cpf", "nome", "senha", "endereco", "telefone", "municipio_id"
];
protected $table = "usuarios";
When executing the form on the route /login
, it is directed to /logar
but no login, no error and the screen is the same as the previous.
"Authenocontroller@log" is probably this. You just misspelled the name of the web route function.
– Ricardo Lucas