'boolean', 'activo' => 'boolean', 'publico' => 'boolean', 'duracion' => 'integer', 'intentos_maximos' => 'integer', 'tiempo_por_pregunta' => 'integer', 'precio' => 'decimal:2', 'fecha_inicio' => 'datetime', 'fecha_fin' => 'datetime', ]; // Examen → Calificación (opcional) public function calificacion() { return $this->belongsTo(Calificacion::class); } /* ============================= | SCOPES ============================= */ public function scopeActivos($query) { return $query->where('activo', true); } public function scopePublicos($query) { return $query->where('publico', true); } public function scopePorProceso($query, $proceso) { return $query->where('tipo_proceso', $proceso); } /* ============================= | ACCESSORS ============================= */ public function getEstaDisponibleAttribute(): bool { $now = now(); if (!$this->activo) { return false; } if ($this->fecha_inicio && $now->lt($this->fecha_inicio)) { return false; } if ($this->fecha_fin && $now->gt($this->fecha_fin)) { return false; } return true; } protected static function booted() { static::creating(function ($examen) { if (empty($examen->slug)) { $examen->slug = Str::slug($examen->nombre) . '-' . uniqid(); } }); } public function areas() { return $this->belongsToMany( Area::class, 'area_proceso' ) ->withPivot('id') ->withTimestamps(); } }