The dynamic property version has a problem known as the "N+1" problem. It makes a new query for each user separately to get the names of the users. The second example makes use of something known as eager loading. You can see how this works with the output query - it collects all the needed user ids, and then makes a single WHERE IN query.

If you only need to work with the property itself, like when we were getting hamsters from the User in the top example, then there is no need to add the small overhead of eager loading. If you do run into an N+1 case this can be a huge performance boost. It's important to understand when you want to add this.

A small note that may save you some frustration. The with('user') syntax refers to the name of the function that holds the relationship you want to eager-load. Most of the time you'll follow Laravel's recommended naming patterns, but should you ever need to stray from that, understand that it is the function name and not the table name or class that you are referring to.

https://eloquentbyexample.com/course/lesson/lesson-12-relationship-queries