1
votes

i am doing multi authentication my front end has a login form with cardno and password. in auth.php

return [
        'multi' => [
            'users' => [
                'driver' => 'eloquent',
                'model'  => App\User::class,
                'table'  => 'users'
            ],
            'frontendUsers' => [
                'driver' => 'eloquent',
                'model'  => App\loginModel::class,
                'table'  => 'frontend_users'
            ]
         ],
         'password' => [
                'email' => 'emails.password',
                'table' => 'password_resets',
                'expire' => 60,
            ],
        ];

in route.php

Route::post('login','auth\loginController@postLogin');

in logincontroller,

public function postLogin(Request $request){
....
    // attempt to do the login
    if (\Auth::attempt('frontendUsers', ['cardno' => '111111', 'password' => '999087787'])) {
           echo "login";
    }
    else {
            echo "failed";
    }
}

in loginModel.php

<?php namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
class loginModel extends Model {

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table    = 'frontend_users';
    //public $timestamps    = false;

 }

when i try to log in i get this error

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\loginModel given, called in C:\xampp\htdocs\elitecard\vendor\laravel\framework\src\Illuminate\Auth\Guard.php on line 390 and defined

2
show us the code of loginModel - Vikas

2 Answers

0
votes

You have to implement the contract Illuminate\Contracts\Auth\Authenticatable in your model and also use the trait Illuminate\Auth\Authenticatable. To use a trait in a class, you have to write the use statement inside the class. The beginning of your loginModel should be like this:

<?php namespace App;

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

class loginModel extends Model implements AuthenticatableContract, CanResetPasswordContract {

    use Authenticatable, CanResetPassword;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'frontend_users';
0
votes

In your model loginModel, try to use the trait called "Authenticatable", or use the Users model instead.