Skip to content

Instantly share code, notes, and snippets.

@tisuchi
Last active September 20, 2017 05:53
Show Gist options
  • Save tisuchi/e8df23b6ec9498a2640f5291e409fe98 to your computer and use it in GitHub Desktop.
Save tisuchi/e8df23b6ec9498a2640f5291e409fe98 to your computer and use it in GitHub Desktop.
Example of Laravel with() - tisuchi.com
<?php
$users = User::with('posts')->get();
foreach($users as $user){
$users->posts; // posts is already loaded and no additional DB query is run
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment