- Remove old any-llm related files (Dockerfile, config.yml, web/, setup-laravel.sh) - Update README.md with new Laravel LLM Gateway documentation - Keep docker-compose.yml with laravel-llm container names - Clean project structure for Laravel-only implementation
90 lines
1.9 KiB
PHP
90 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class ApiKey extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'api_keys';
|
|
protected $primaryKey = 'token';
|
|
public $incrementing = false;
|
|
protected $keyType = 'string';
|
|
|
|
protected $fillable = [
|
|
'token',
|
|
'user_id',
|
|
'key_alias',
|
|
'key_name',
|
|
'permissions',
|
|
'models',
|
|
'metadata',
|
|
'expires',
|
|
];
|
|
|
|
protected $casts = [
|
|
'permissions' => 'array',
|
|
'models' => 'array',
|
|
'metadata' => 'array',
|
|
'expires' => 'datetime',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Get masked version of the key
|
|
*/
|
|
public function getMaskedKeyAttribute(): string
|
|
{
|
|
return substr($this->token, 0, 8) . '...' . substr($this->token, -4);
|
|
}
|
|
|
|
/**
|
|
* Check if key is active (not explicitly marked inactive)
|
|
*/
|
|
public function getIsActiveAttribute(): bool
|
|
{
|
|
// For now, consider all keys active unless explicitly deleted
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Check if key is expired
|
|
*/
|
|
public function getIsExpiredAttribute(): bool
|
|
{
|
|
if (!$this->expires) {
|
|
return false;
|
|
}
|
|
return $this->expires->isPast();
|
|
}
|
|
|
|
/**
|
|
* Get last used at timestamp
|
|
*/
|
|
public function getLastUsedAtAttribute()
|
|
{
|
|
$latestLog = $this->usageLogs()->latest('timestamp')->first();
|
|
return $latestLog ? $latestLog->timestamp : null;
|
|
}
|
|
|
|
public function gatewayUser()
|
|
{
|
|
return $this->belongsTo(GatewayUser::class, 'user_id', 'user_id');
|
|
}
|
|
|
|
// Alias for backwards compatibility
|
|
public function user()
|
|
{
|
|
return $this->gatewayUser();
|
|
}
|
|
|
|
public function usageLogs()
|
|
{
|
|
return $this->hasMany(UsageLog::class, 'api_key', 'token');
|
|
}
|
|
}
|