Den Kindern hat der Besuch im Planetarium Spaß gemacht. (The children enjoyed going to the planetarium.)
Why is it "den Kindern hat der Besuch", instead of "die Kinder haben den Besuch"?
a) Den Kindern hat der Besuch im Planetarium Spaß gemacht.
b) Der Besuch im Planetarium hat den Kindern Spaß gemacht.
c) Spaß hat den Kindern der Besuch im Planetarium gemacht.
'Den Kindern' is in the dative case because, in the German sentence construction, 'the children' is the indirect object (a.k.a. dative object) of the verb 'Spaß machen'. The subject in the sentence is 'der Besuch', which therefore is in the nominative case.
(Why the preposition 'im' (in dem)? Because in German, 'der Besuch' is in a location, not 'to/into somewhere'. It would be different for a 'trip to the planetarium': der Ausflug ins Planetarium.)
I see many answers stating that den Kindern is the object and der Besuch is the subject, but that might seem confusing to English speakers when translating. I would suggest the following English version of the sentence:
The children enjoyed their visit to the planetarium.
Which has almost the same structure — most notably, the positions of the children and the visit are identical.
But this English sentence uses a totally different verb than the German example sentence. to enjoy something is a ‘passivistic’ verb (I’m not sure what a proper name would be), namely that the object (the planetarium) is doing something to you (making you happy). Compare to a sentence with an ‘activistic’ verb:
The children threw stones at the planetarium.
Where the subject of the sentence is actually performing the action.
I’m not sure of the grammatical categories, but I can imagine the children to have different ones in the two sentences, because one is ‘activistic’ and the other isn’t.
The German sentence, on the other hand, contains an ‘activistic’ verb to express the same thought:
Den Kindern hat der Besuch im Planetarium Spaß gemacht.
The actual sentence structure is a lot closer to the throwing stones example above, because it is, in fact the visit that is ‘activistically’ doing something to the children, namely giving them enjoyment. This is reflected in the sentence’s grammar, which gives the visit to the planetarium the subject role and thus the nominative case, while the children are given an object rule and a dative case.
Totally redundant reply: It's Dativ ("Wemfall"). Wem hat der Besuch Spaß gemacht? Den Kindern.
You can't start with ""die Kinder haben den Besuch...", because the case is wrong. If you correct this problem, you end up with something like
Die Kinder haben am Besuch des Planetariums Spaß gehabt.
Or you could use a different translation for "enjoy":
Die Kinder haben den Besuch des Planetariums genossen.