vendredi 22 janvier 2016

Argument 1 passed to Illuminate\Auth\Guard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable error in laravel5.1

I am using laravel 5.1 for my project. I am trying to authenticate my built in model instead of laravel's own User model.

My model name is Registration_Model
my table is registration

from Laravel 5.1 multiple authentication i did what he said. the auth.php file is

    return [
'multi' => [
    'jobseeker' => [
        'driver' => 'eloquent',
        'model'  => App\Registration_Model::class, // Model Class
        'table'  => 'regist' // jobseeker table
    ],
 ],
 'password' => [
       'email' => 'emails.password',
       'table' => 'password_resets',
       'expire' => 60,
  ]
 ];

My route.php file is

Route::resource('/', 'RegistrationController');
Route::get('register', function () {
    return view('project.register');
});
Route::post('route_register','RegistrationController@store');

// Authentication routes...
Route::get('auth/login', 'Auth\AuthRegistrationController@getLogin');
Route::post('auth/login', 'Auth\AuthRegistrationController@postLogin');
// Route::post('auth/login', 'Auth\AuthController@authenticate');
Route::get('auth/logout', 'Auth\AuthRegistrationController@getLogout');

// Registration routes...
Route::get('auth/register', 'Auth\AuthRegistrationController@getRegister');
Route::post('auth/register','Auth\AuthRegistrationController@postRegister');

and my AuthRegistrationController.php file is

    <?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Requests\Request;
use Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use App\Http\Controllers\RegistrationController;
use App\Registration_Model;

class AuthRegistrationController extends Controller
{

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;  
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }  
    protected function validator(array $data)
    {
        return Validator::make($data, [

            'email' => 'required|email|max:255|unique:registration',
            'password' => 'required|confirmed|min:3',
        ]);
    }
    protected function create(array $data)
    {
        return Registration_Model::create([

            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
    protected $redirectPath = 'register'; 
   protected $loginPath = '/auth/login';
}

and i am getting error message when try registration.

  1. ErrorException in Guard.php line 430: Argument 1 passed to Illuminate\Auth\Guard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\Registration_Model given. and i am getting error message when try login
  2. ErrorException in EloquentUserProvider.php line 110: Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\Registration_Model given, called in C:\xampp\htdocs\project_2016\vendor\laravel\framework\src\Illuminate\Auth\Guard.php on line 390 and defined


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire