Assuming you are using a non-ancient or edge-case laptop it will have some type of Lithium based battery - and my answer makes this assumption.
The worst things for your battery are - in rough order of how stressful they are:
- Fully discharging your battery, or approaching full discharge. This is head and shoulders the worst thing you can do.
- Heating your battery significantly (which could be caused by charging it while drawing power from it, or leaving it in an environment that gets hot.
- Fully charging your battery.
- Leaving your battery at full discharge.
From a longevity point of view, keeping the battery between 40 and 60% charge will increase its lifespan significantly, but will of-course reduce the runtime. (This is why cellphones and laptops are shipped with batteries charged to about 60%) Some laptops have this functionality built into the "BIOS" - including most Dells, and, I think Lenovo's - This would be "the trick" you are looking for.
If you are able to predict when you will need to run it on battery, increasing it to charge close to fully, then running it down is a lot better then leaving it to charge fully overnight - although it is a pain.
Regardless of what you do, the battery will gradually deteriorate. Even unused, the warmer the environment, the faster it will die - but expect it to loose between 2 and 6% per year under normal conditions.
My guess as to why this persons battery keeps dying after a couple of months is that they are allowing the battery to run near or fully flat between charges. (I am assuming they have gone through multiple batteries and its not a faulty battery)
https://batteryuniversity.com/index.php/learn/article/lithium_based_batteries and the pages linked in it are an excellent source of information about Lithium battery characteristics - including results of testing they have done.