title: Does Eloquent handle caching of related entities?
body: <p>I'm exploring Laravel's Eloquent as a drop-in replacement for my project's current, home-grown active record data layer.  Currently, I have a class <code>User</code> that supports a many-to-many relationship with another class, <code>Group</code>.  My current implementation looks something like:</p>
  
  <pre><code>class User {
  
      protected $_groups;  // An array of Group objects to which this User belongs
  
      public function __construct($properties = []){
          ...
      }
  
      public function groups() {
          if (isset($_groups))
              return $_groups;
          else
              return $_groups = fetchGroups();
      }
  
      private function fetchGroups() {
          // Lazily load the associated groups based on the `group_user` table
          ...
      }
  
      public function addGroup($group_id) {
          // Check that the group exists and that this User isn't already a member of the group.  If so, insert $group_id to $_groups.
          ...
      }
  
      public function removeGroup($group_id) {
          // Check that the User is already a member of the group.  If so, remove $group_id from $_groups.
          ...
      }
  
      public function fresh() {
          // Reload user and group membership from the database into this object.
          ...
      }
  
      public function store() {
          // Insert/update the user record in the `user` table, and insert/update/delete records in `group_user` based on the contents of `$_group_user`.
          ...
      }
  
      public function delete() {
          // If it exists, delete the user record from the `user` table, and delete all associated records in `group_user`.
          ...
      }
  }
  </code></pre>
  
  <p>As you can see, my class:</p>
  
  <ol>
  <li>Performs lazy loading of related groups, caching after the first time they're queried;</li>
  <li>Maintains an internal representation of the <code>User</code>'s relationship with their <code>Group</code>s, updating in the database only when <code>store</code> is called;</li>
  <li>Performs sanity checks when establishing relationships, making sure that a <code>Group</code> exists and is not already related to the <code>User</code> before creating a new association.</li>
  </ol>
  
  <p>Which, if any of these things, will Eloquent automatically take care of for me?  Or, is my design flawed in some way that Eloquent can solve?</p>
  
  <p>You can assume that I will re-implement <code>User</code> as <code>User extends Illuminate\Database\Eloquent\Model</code> and use Eloquent's <code>belongsToMany</code> as a replacement for my current <code>fetchGroups</code> method.</p>