Skip to content

Commit

Permalink
Extend getOriginal method to decrypt any encrypted fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwain Maxwell committed Apr 15, 2016
1 parent 3a83eb8 commit f58885e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Dtisgodsson/Elocrypt/ElocryptTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,37 @@ public function attributesToArray()

return $attributes;
}

/**
* Get the model's original attribute values.
*
* @param string $key
* @param mixed $default
* @return array
*/
public function getOriginal($key = null, $default = null)
{
$original = parent::getOriginal($key, $default);

if(!isset($this->encryptable))
{
return $original;
}

foreach ($this->encryptable as $key)
{
if ( ! isset($original[$key])) continue;

try
{
$original[$key] = Crypt::decrypt($original[$key]);
}
catch(DecryptException $exception)
{
//Do nothing, attribute already exists
}
}

return $original;
}
}

0 comments on commit f58885e

Please sign in to comment.