Laravel 5 authentication shows no errors

Asked

Viewed 686 times

1

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

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
  • Friend, post the code you already have, will help and MUCH will help you.

  • I posted, if you need any more.

  • Look at the answer I posted.

1 answer

2


For this I usually use Session.

For example, 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 there on the login page I put, if it is Blade, if it is not use the normal PHP same.

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

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

Not.

  • 1

    Thank you, that way it worked.

  • Mark it as the right answer if it really helped you.

Browser other questions tagged

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