There certainly are advantages to purchasing the property in the name of a foreign or Spanish based Company in Spain. You can either create a Spanish Limited Company and own the property indirectly by owning shares in the said Company.
This option is recommended when there is a need for relative anonymity, in which case you obviously cannot be administrator of the company –all information about administrators is public and can be easily found in the Spanish Mercantile Registry-.
It has also been asserted that purchasing via a company may reduce the liability to pay inheritance taxes in the future. However it should be borne in mind that the European Court of Justice has recently ruled that the Spanish tax authorities cannot charge different rates of inheritance tax for residents and non-residents and the relevant Spanish Laws have been modified accordingly, by Ley 26/2014, which came into force on January 1st, 2015.
The new legislation provides that European Union citizens, ordinarily resident in another European country, may benefit from the same deductions as are available to residents of the region in Spain in which their assets are located. Therefore, this tax liability may already be much lower than previously was the case.
It is also worth bearing in mind that, if you put the property in the name of a foreign company that does nothing other than merely hold this property in Spain, it is possible that the beneficiaries will need to pay inheritance taxes in Spain for having inherited a Spanish property, even though the property is transmitted in the country of origin together with the shares, if it is construed that the only objective of the company is to evade taxes. There would also be potential liability to fines in such as case.