'boolean', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /* ================= RELACIONES ================= */ public function examenes() { return $this->belongsToMany( Examen::class, 'examen_area', 'area_id', 'examen_id' )->withTimestamps(); } /* ================= SCOPES ================= */ public function scopeActivas($query) { return $query->where('activo', true); } public function scopeInactivas($query) { return $query->where('activo', false); } public function scopePorCodigo($query, $codigo) { return $query->where('codigo', strtoupper($codigo)); } public function scopePorNombre($query, $nombre) { return $query->where('nombre', 'like', "%{$nombre}%"); } public function scopeDeAcademia($query, $academiaId) { return $query->where('academia_id', $academiaId); } /* ================= ACCESSORS ================= */ public function getEstadoAttribute() { return $this->activo ? 'Activo' : 'Inactivo'; } public function getEstadisticasAttribute() { return [ 'total_cursos' => $this->cursos()->count(), 'total_examenes' => $this->examenes()->count(), ]; } public function getCursosCountAttribute() { return $this->cursos()->count(); } public function getExamenesCountAttribute() { return $this->examenes()->count(); } public function cursos() { return $this->belongsToMany(Curso::class, 'area_curso')->withTimestamps(); } public function procesos() { return $this->belongsToMany(Proceso::class, 'area_proceso') ->withPivot('id') ->withTimestamps(); } }