title: Laravel Eloquent - Encrypting/Decrypt Data on call
body: <p>I can use <code>Crypt</code> to encrypt/decrypt my data. I want to encrypt some information in my db (such as the name, email, phone number to name a few).</p>
  
  <p>Assuming that I want EVERYTHING to be encrypted, I want to be able to do this in the background by itself, which I can perform by overwriting the <code>create</code> and <code>save</code> functions:</p>
  
  <pre><code>// For instance, the save() function could become
  public function save(array $options = array())
  {
      foreach ($this-&gt;attributes as $key =&gt; $value)
      {
          if (isset($value)) $this-&gt;attributes[$key] = Crypt::encrypt($value);
      }
      return parent::save($options);
  }
  </code></pre>
  
  <p>Now, I want the decryption to be performed the same way, so that when I say <code>User::find($id)</code>, the returned <code>$user</code> is already decrypted. Also other functions such as <code>firstOrFail()</code> <code>get()</code> <code>first()</code> and all to work as well.</p>
  
  <p>I also would like this functionality to be extended when I use relationships (so <code>User::with('someOtherTable')-&gt;find($id)</code> also work).</p>
  
  <p>Would this be possible? If this is not possible, I am thinking of creating a helper function <code>decyrpt()</code></p>
  
  <pre><code>function decrypt($array)
  {
      if (!is_array($array)) return Crypt::decrypt($array);
  
      $result = [];
  
      foreach($array as $key =&gt; $value) $result[$key] = decrypt($value);
  
      return $result;
  }
  </code></pre>
  
  <p>And pass all my results through this first, and then start using them, but it would be nicer if Laravel would provide this, or if there was a "Laravel Way" of doing this.</p>