'string', 'fecha_nacimiento' => 'date', 'edad' => 'integer', 'id_club_actual' => 'integer', 'id_club_origen' => 'integer', 'activo' => 'boolean', 'reset_expira' => 'datetime', ]; public function getCategoriaCalculadaAttribute() { if (!$this->fecha_nacimiento) return 'Sin categoría'; // Calculate age for the current year. (Categoría U15 is for players turning 14 and 15 in the current year). // That means current_year - birth_year $edadCategoria = date('Y') - $this->fecha_nacimiento->format('Y'); $categoria = Categoria::where('edad_min', '<=', $edadCategoria) ->where('edad_max', '>=', $edadCategoria) ->first(); return $categoria ? $categoria->nombre : 'Sin categoría'; } public function clubActual() { return $this->belongsTo(Club::class, 'id_club_actual', 'id_club'); } public function clubOrigen() { return $this->belongsTo(Club::class, 'id_club_origen', 'id_club'); } public function equipos() { return $this->belongsToMany(Equipo::class, 'jugador_equipo', 'id_jugador', 'id_equipo') ->withPivot('fecha_alta'); } }