dimanche 19 mai 2019

authenticate email and password from custom guard using attempt in laravel

that's my controller that holds the api function:

public function loginsub(Request $request)
{ 
   $credentials = $request->only('email', 'password');

    if(Auth::guard('sub_users')->attempt($credentials))
    { 
        $user = Auth::guard('sub_users'); 
    }
}

guards from auth.php config:

 'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],

         'sub_users' => [
            'driver' => 'passport',
            'provider' => 'sub_users'
        ],
    ],

i get this error:

"message": "Method attempt does not exist.", "status_code": 500

i'm trying to login with subuser model :

<?php

namespace App;

use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class sub_users extends Authenticatable
{
    use HasApiTokens, Notifiable;

   /**
    * The attributes that are mass assignable.
    *
    * @var array
    */
    protected $fillable = [
        'name', 'email', 'password','type','login_ip',
    ];

    /**
    * The attributes that should be hidden for arrays.
    *
    * @var array
    */
    protected $hidden = [
        'password', 'remember_token',
    ];    
}

i've also tried check() instead of attemp but it didnt work thanks in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire