title: Laravel json response returns encrypted data
body: <p>I'm using an Encryptable trait to encrypt my data for the a Room model.</p>
  
  <p>RoomController <em>(/rooms)</em> returns the decrypted data but ApiRoomController <em>(/api/rooms)</em> does not.
  How could I make it returns the decrypted data?</p>
  
  <p><strong>Encryptable Trait</strong></p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>trait Encryptable
  {
      public function getAttribute($key)
      {
          $value = parent::getAttribute($key);
          if (in_array($key, $this-&gt;encryptable) &amp;&amp; $value !== '' &amp;&amp; $value !== null ) {
              $value = Crypt::decrypt($value);
          }
  
          return $value;
      }
  
      public function setAttribute($key, $value)
      {
          if (in_array($key, $this-&gt;encryptable)) {
              $value = Crypt::encrypt($value);
          }
  
          return parent::setAttribute($key, $value);
      }
  }
  </code></pre>
  
  <p><strong>RoomController index function</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>public function index()
  {
      $rooms = Room::select('id', 'name')-&gt;get()-&gt;sortBy('name')-&gt;values()-&gt;all();
  
      return view('rooms.index')-&gt;withRooms($rooms);
  }
  </code></pre>
  
  <p><strong>ApiRoomController index function</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>public function index()
  {
      $rooms = Room::select('id', 'name')-&gt;get()-&gt;sortBy('name')-&gt;values()-&gt;all();
  
      return response()-&gt;json($rooms);
  }
  </code></pre>