Error logging in to Laravel

Asked

Viewed 317 times

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.

  • 1

    "Authenocontroller@log" is probably this. You just misspelled the name of the web route function.

1 answer

1


You’re not calling the action correct, substitute:

Route::post('/logar', 'AutenticacaoController@login')->name('autenticacao.logar');

For:

Route::post('/logar', 'AutenticacaoController@logar')->name('autenticacao.logar');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.