Skip to content

Instantly share code, notes, and snippets.

@RyanNutt
Last active July 31, 2019 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanNutt/a2dc6282f8223e9e91f97a7a03c7697d to your computer and use it in GitHub Desktop.
Save RyanNutt/a2dc6282f8223e9e91f97a7a03c7697d to your computer and use it in GitHub Desktop.
Laravel Eloquent query to pull the authors with the most posts connected by a hasMany relationship

Laravel Eloquent Query by Relationships

Needed this for a WordPress to Laravel conversion project I'm working on. For the footer I needed to pull the top authors, sorted by the number of posts associated with them. On the site, it's actually fonts, but posts makes more sense for most people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment