update controllers logic

This commit is contained in:
root
2026-04-23 00:04:35 -04:00
parent 1977a513df
commit ca4ba272fc
353 changed files with 13402 additions and 1301 deletions
+36 -15
View File
@@ -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();
}
/* ============================================================