update controllers logic
This commit is contained in:
+36
-15
@@ -18,12 +18,15 @@ class User extends Authenticatable implements JWTSubject
|
||||
use HasApiTokens;
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
protected $table = 'users';
|
||||
|
||||
protected $fillable = [
|
||||
'school_id',
|
||||
'firstname',
|
||||
'password',
|
||||
'account_id',
|
||||
'lastname',
|
||||
'firstname',
|
||||
'gender',
|
||||
'cellphone',
|
||||
'email',
|
||||
@@ -33,20 +36,19 @@ class User extends Authenticatable implements JWTSubject
|
||||
'state',
|
||||
'zip',
|
||||
'accept_school_policy',
|
||||
'is_verified',
|
||||
'status',
|
||||
'is_suspended',
|
||||
'failed_attempts',
|
||||
'password',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'token',
|
||||
'account_id',
|
||||
'user_type',
|
||||
'rfid_tag',
|
||||
'school_id',
|
||||
'failed_attempts',
|
||||
'last_failed_at',
|
||||
'semester',
|
||||
'school_year',
|
||||
'rfid_tag',
|
||||
'last_failed_at',
|
||||
'status',
|
||||
'is_suspended',
|
||||
'is_verified',
|
||||
'token',
|
||||
'updated_at',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@@ -71,9 +73,28 @@ class User extends Authenticatable implements JWTSubject
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
public function getJWTCustomClaims()
|
||||
public function getJWTCustomClaims(): array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'name' => trim(($this->firstname ?? '').' '.($this->lastname ?? '')),
|
||||
'roles' => $this->roleNamesLikeCodeIgniter(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Role names joined from `user_roles` + `roles`, matching CodeIgniter `AuthController::apiLogin` (no roles.is_active filter).
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function roleNamesLikeCodeIgniter(): array
|
||||
{
|
||||
return DB::table('user_roles')
|
||||
->join('roles', 'roles.id', '=', 'user_roles.role_id')
|
||||
->where('user_roles.user_id', $this->id)
|
||||
->pluck('roles.name')
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
|
||||
Reference in New Issue
Block a user