Probably the easiest companion to get this with is Codsworth. You can find him in front of your old home after leaving the vault, pretty hard to miss.
Now Codsworth loves it when you mod your weapons or armor. So every time you visit your preferred settlement to mod something you will make (
or at least have a chance to make) Codsworth happy. Note that it has a cooldown until you receive a new like from him.
Old method, obviously patched, sadly:
*** Spoiler - click to reveal ***As B0ngAAA stated in the comments it can be done faster by quicksaving your game and reload it, then mod something new or just switch between mods you already own as you can see in the video below and Codsworth will give you a like again. Be aware that you won't make progress towards the 'armed and dangerous' achievement if you just keep switching between mods you already own. https://www.trueachievements.com/TheTrismegistos.htm mentioned in the comments that you can switch a weapon and an armor mod everytime you save and reload the game to receive 2 likes each time. This might still take quite a while (30 min+) if you do it right from scratch after you met Codsworth. This method also works with every other companion who likes if you mod weapons/armor.
If you want to boost it you can go sleeping for 48h and then mod something again and receive a new like from codsworth.
If you pay enough attention you can see a popup in the top left corner of the screen once the relationship increases. There are several stages of how much he likes you (
neutral->respect->love->idolize). Every time it increases he will start a conversation with you by himself if he's somewhere around you.
If you have him at maximum it will net you the perk 'robot sympathy' which gives you +10 damage resistance for energy weapons from robots.
In case you have him with you as a companion, he also likes generosity, giving away items and nice or peaceful behavior.
What he doesn't like is selfish behavior, murdering non-hostiles, picking owned (
red) locks, speech success, pickpocketing and theft.
If you don't switch between already owned mods you can make progress towards the 50 weapon mod achievement while increasing the relationship with Codsworth;
if you want to maximize any other companions relationship, you can find a list of what they like, what not and what perk they net you on this site;http://www.gameranx.com/features/id/31624/article/fallout-4-...note; sometimes it happens that you have to do something your companion doesn't like or you do it by accident and haven't saved your game recently to just load it and have it undone. But that's no reason to worry, it will not prevent you from reaching maximum relationship with them, it will just take a bit longer (
except you do something to make them hostile like murdering them or someone friendly, try to avoid that ).
*if you're going to vote negative please tell why in the comments so I can improve the solution if needed (
in case something gets patched or anything alike), thanks!
Thanks to
TonySki for spell checking the solution by putting it through Microsoft Word spelling and grammar check!