Argument 1 passed to Illuminate \ Auth \ EloquentUserProvider :: validateCredentials () LARAVEL 5.2

1

A few days with this error and I do not know what is due, I was trying to make a login, with the make: auth of Laravel, the connection to the database is good, the fields exist and the routes work correctly , but when authenticating, this error appears:

ErrorException in EloquentUserProvider.php line 114: Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\User given, called in C:\xampp\htdocs\HTDOCS_PHP\Laravel_Dulius\vendor\laravel\framework\src\Illuminate\Auth\SessionGuard.php on line 378 and defined

so I tried to do another login by hand, but it happens to me exactly the same, if I put the data incorrectly it puts me the message that I have put myself for wrong message, but if I put the data well I jump the same message. These are the data of the new login

routes

Route::get('/home', 'HomeController@index');
Route::get('inicia','autenticandoController@inicioSession');
Route::post('loginx','autenticandoController@loginx');

controller

    <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use Auth;

class autenticandoController extends Controller
{

    public function inicioSession()
    {
        return View('inicioSession');
    }

    public function loginx(Request $request)
    {

        if(Auth::attempt(
                array(
                            'email'=>$request->email,
                            'password'=>$request->password,
                        )))
        {

            $respuesta = ' correo  '.$request->email;
            $respuesta += ' password '.$request->password;
            return  $respuesta;
        }
        else
        {
            return 'fallo login';
        }

    }

}

view

@extends('layouts.appinicia')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Inicia Session</div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" method="POST" action="{{ url('/loginx') }}">
                        {!! csrf_field() !!}

                        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">Correo Electronico</label>

                            <div class="col-md-6">
                                <input type="email" class="form-control" name="email" value="{{ old('email') }}">

                                @if ($errors->has('email'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">Contraseña</label>

                            <div class="col-md-6">
                                <input type="password" class="form-control" name="password">

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" name="remember"> Recuerdame
                                    </label>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    <i class="fa fa-btn fa-sign-in"></i>Iniciando Session
                                </button>

                                <a class="btn btn-link" href="{{ url('/password/reset') }}">Olvidaste tu password?</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

User model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;


class User extends Model 
{
    protected $table = 'users';

    protected $fillable = [
        'nombre', 'apellido', 'tipo','email','password'
    ];

      public function getlistaNombreCompletoAttribute()
    {

        return $this->nombre.'  '.$this->apellido;
    }

    public function relacionPerfilesUsuario()
    {   
        return $this->hasOne('App\perfiles_usuario');
    }

    public function setPasswordAttribute($valor)
    {
        if(!empty($valor))
        {
         $this->attributes["password"]= bcrypt($valor);
        }
    }
}

This is the custom login, the view is the same as that of make: auth, except that I have modified some routes and names. As I say I have tried in both cases by different ways and the result is the same. Why can it be?

    
asked by KurodoAkabane 26.04.2016 в 12:04
source

2 answers

2

Normally you should have something like that in your User :

<?php 

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Auth\Authenticatable;

class User extends Model implements AuthenticatableContract {

    use Authenticatable;

    // ...

}
    
answered by 26.04.2016 / 16:51
source
1

To clarify a little what happened, is that when you login the class does not consult internally for an instance of App\User but for the interface Illuminate\Contracts\Auth\Authenticatable , that is why the code above solved the problem and that is implementing this interface within the App \ User. On the other hand, it makes use of Illuminate \ Auth \ Authenticatable , which is a trait that implements the methods of Illuminate\Contracts\Auth\Authenticatable . I hope I have clarified a bit the reason for the error and the reason for the solution;)

Greetings.

    
answered by 30.04.2016 в 17:23