title: Encrypt/Decrypt DB fields in laravel
body: <p>I am encrypting/decrypting the DB field values in Laravel through accessors and mutators, which is working fine in normal eloquent transactions.</p>
  
  <pre><code>class Person extends Model
  {
      use Notifiable;
      protected $table = 'person';
  
      public function getFirstNameAttribute($value)
      {
          return Crypt::decryptString($value);
      }
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $guarded = array();
  
      protected function user()
      {
          return $this-&gt;belongsTo('App\Models\User', 'useraccount_id', 'id');
      }
  }
  </code></pre>
  
  <p>But the encryption and decryption not working under the following conditions</p>
  
  <ol>
  <li>Eloquent relationships</li>
  <li>DB raw queries</li>
  </ol>
  
  <p>Working</p>
  
  <pre><code>$person = Person::find($person_id);
  $person-&gt;firstName;
  </code></pre>
  
  <p>Not Working</p>
  
  <pre><code>$user = User::find($user_id);
  $user-&gt;person-&gt;firstName;
  </code></pre>