I am trying to make login and logout function in model/controller named Admin and there I already have User model/controller but it’s not for the Auth purpose, when I am trying to call Auth::attempt() or Auth::logout() it returns this error
JavaScript
x
Call to undefined method AppModelsUser::getAuthIdentifierName()
here is my code
the Admin model
JavaScript
<?php
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateFoundationAuthUser as Authenticatable;
class Admin extends Authenticatable
{
use HasFactory;
protected $fillable = ['username', 'password'];
protected $hidden = ['password'];
}
the User model
JavaScript
<?php
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
class User extends Model
{
use HasFactory;
protected $fillable = ['name', 'national_id', 'check_lab', 'check', 'visit_date_to',
'user_password', 'report_time', 'reference_id', 'passport_id', 'result',
'visit_date_from',
'embassy', 'report_date'];
}
Advertisement
Answer
If you want to use Admin
Modal instead of the User
model for auth then you need to change the default Modal in config/auth.php
From
JavaScript
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => AppModelsUser::class,
],
To
JavaScript
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => AppModelsAdmin::class,
],