mercredi 31 août 2016

multi auth not working in laravel 5.1

I am using Laravel 5.1 and I need multiple login in my project so I am trying Kbwebs\MultiAuth and Sarav\Multiauth for multi auth, both are worked with user model model but unfortunately when I use TenderApplicant model Auth::attempt return false every times.

I searched all over and trying to figure out the problem

This is my code

app.php

'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
    Illuminate\Auth\AuthServiceProvider::class,
    Sarav\Multiauth\MultiauthServiceProvider::class,
    ...

auth.php

return [
'multi' => [
    'admin' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
        'table' => 'sa_users',
    ],
    'user' => [
        'driver' => 'eloquent',
        'model'  => App\Models\TenderApplicant::class,
        'table'  => 'tender_applicant',
    ],
],
'password' => [
    'email'  => 'emails.password',
    'table'  => 'sa_password_resets',
    'expire' => 60,
],

];

AuthController.php

class AuthController extends Controller
{

use AuthenticatesAndRegistersUsers, ThrottlesLogins;

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

public function userAuth(Request $request)
{
    $this->validate($request, ['email' => 'required','password' => 'required']);

    $email      = $request->input('email');
    $password   = $request->input('password');
    var_dump(Auth::attempt("user", ['email' => 'awal.ashu@gmail.com', 'password' => '123456']));
}

return false for user but admin worked perfected.

TenderApplicant.php

namespace App\Models;

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 TenderApplicant extends Model implements AuthenticatableContract, CanResetPasswordContract
{
    use Authenticatable, CanResetPassword;
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table      = 'tender_applicant';
    protected $primaryKey = 'TE_APP_ID';
    const CREATED_AT      = 'CREATED_AT';
    const UPDATED_AT      = 'UPDATED_AT';

    protected $fillable = [
                        'TENDER_ID', 
                        'SCHEDULE_ID', 
                        'PR_DETAIL_ID', 
                        'NID', 
                        'PR_CATEGORY', 
                        'PR_TYPE', 
                        'APPLICANT_NAME',
                        'EMAIL',  
                        'APPLICANT_PHONE', 
                        'PASSWORD', 
                        'HOLDING_NO', 
                        'IS_TE_SC_BOUGHT', 
                        'TE_SC_AMOUNT', 
                        'TE_SC_DATE', 
                        'SPOUSE_NAME', 
                        'BID_AMOUNT',
                        'BG_AMOUNT', 
                        'BG_AMOUNT_TEXT',
                        'BANK_ID',
                        'B_DRAFT_NO', 
                        'B_DRAFT_DATE', 
                        'B_DRAFT_ATTACHMENT', 
                        'IS_SELECTED', 
                        'IS_ACTIVE', 
                        'CREATED_BY', 
                        'UPDATED_BY'
                    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $guarded = ['TE_APP_ID'];

    /**
     * Password need to be all time encrypted.
     *
     * @param string $password
     */
    public function setPasswordAttribute($password)
    {
        $this->attributes['PASSWORD'] = bcrypt($password);
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire