* * @version 1.0.0 */ class Arco extends Model { protected $table = 'arcos'; protected $fillable = [ 'nombre', 'ip_address', 'ubicacion', 'activo' ]; protected $casts = [ 'activo' => 'boolean', 'created_at' => 'datetime', 'updated_at' => 'datetime' ]; protected $hidden = [ 'api_token' ]; protected static function boot() { parent::boot(); static::creating(function ($arco) { if (!$arco->api_token) { $arco->api_token = Str::random(64); } }); } /** * Relación con detecciones */ public function detecciones(): HasMany { return $this->hasMany(Detection::class, 'arco_id'); } /** * Scope para obtener solo arcos activos */ public function scopeActivos($query) { return $query->where('activo', true); } /** * Buscar arco por IP */ public static function buscarPorIp(string $ip): ?self { return self::where('ip_address', $ip)->first(); } /** * Buscar arco por API token */ public static function buscarPorToken(string $token): ?self { return self::where('api_token', $token)->first(); } /** * Regenerar API token */ public function regenerarToken(): string { $this->api_token = Str::random(64); $this->save(); return $this->api_token; } }