Like the other comments suggested, Facebook's advertising algorithms are a very closely held secret. However, we can make some assumptions about how they work. Below is my personal speculation:
Search history
You also mentioned you "googled something". That adds another element to the equation, now we have a google account potentially tied to this activity as well. It is very possible that those two ad services have shared your data, or that the website you visited shared your data. In addition, patterns will emerge in your search history. If you really like a certain model of car, your searches, across all your devices, will have a higher concentration of those types of searches than other users.
Connection information
You have a public IP address, from that address, how many facebook accounts have ever signed in? Just you? Maybe your flatmates or family? How many google accounts? What kind of housing do you live in? Do you live in a one room apartment? Or a large house? Your IP address could point back to this, but probably your search and posting history already gave google and facebook a pretty good idea of your living arrangement. So assuming you live alone, it's rather easy to be able to determine both your phone and your laptop both belong to you. If you do not live alone, it could be more difficult, but still not impossible. When your phone is not at your home, your computer is turned off. When your phone returns home, that computer turns on. By comparing what computers are on and what phones are home over a long enough amount of time, both devices could be pinpointed back to their owner rather easily.
Services
What services are you signed into? Are any of those services the same across both devices? If so, maybe one of those services sold your information. Even if you don't use connected services, you could still be tracked based on your unrelated services usage history. You searched for recipes for apple pie on your computer, then walked into the kitchen and searched for the pie recipe app on your phone. Once could be a happenstance, but if that becomes a regular occurrence, then it would be safe to assume both devices belong to the same person.
Geolocation.
Your phone's location is very accurate. How strong is your connection to your router at any given point in your house? Answer, it varies. Your phone and your computer will have the same connection strength if they are in the same location. This is one of the ways devices can determine where they are, but it can also be used to determine that both devices are being used by the same person.
Connected devices
Do you use headphones? Airpods? Any bluetooth device? Have those bluetooth peripherals ever been connected to both devices? Do those devices switch over from one device to the other when one is powered on or when the other receives a phone call? The patterns of your peripheral connections could also be used to pinpoint what devices you use.
Conclusion
All and all it's probably not just any one of these things, but rather a mixture of all of them to build a confidence score of what devices belong to which users. It might seem ridiculous that a company would go to all that effort just to show you ads, but keep in mind that these algorithms are very easy to run, and advertising is very, very big business. When there is that much money on the line, it's not surprising that companies will put a lot of effort into serving the most targeted ads.