Laravel 5 authentication does not display errors

1

Good afternoon, I'm using Laravel 5 to redo a system and on login screen when authentication is not done the user is redirected to the form again but I can not return any errors.

Model User

protected $connection = 'pgsql2';
protected $primaryKey = 'cod_funcionario';
public $timestamps = false;
protected $table = 'funcionarios';
protected $fillable = ['login', 'senha'];
protected $hidden = ['senha', 'remember_token'];

public function getAuthPassword()
{
    return $this->senha;
}

public function setSenhaAttribute($value)
{
    $this->attributes['senha'] = bcrypt($value);
}

AuthController.php

protected $redirectPath = '/admin';
protected $loginPath = '/admin/auth/login';

public function __construct()
{
    $this->middleware('guest', ['except' => 'getLogout']);
}

protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|confirmed|min:6',
    ]);
}

protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => $data['password'],
        //'password' => bcrypt($data['password']),
    ]);
}

public function postAdminLogin()
{
    if (Auth::attempt(['login' => Request::input('login'), 'password' => Request::input('senha')]))
    {

        return redirect()->intended('admin');
    }
    else{
        return Redirect::to('admin/auth/login');

}

and in the view I'm trying to display the errors as follows:

@if (count($errors) > 0)
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{!! $error !!}</li>
            @endforeach
        </ul>
    </div>
@endif
    
asked by anonymous 03.12.2015 / 20:12

1 answer

2

For this I generally use Session .

For example, you gave login error, do this in your else .

else{
     Session::flash('alert', 'Deu pau no login, tente de novo');
      return Redirect::to('admin/auth/login');
}

From the login page I put it, if it is a blade, if it does not use the normal PHP itself.

@if(Session::has('alert'))
    {!! Session::get('alert') !!}
@endif

This Session::flash works only from page to page. Top, right?

No.

    
03.12.2015 / 20:19