Skip to content

Commit

Permalink
Merge pull request #4 from Dwa1n/master
Browse files Browse the repository at this point in the history
Extend getOriginal method to decrypt any encrypted fields
  • Loading branch information
darrentaytay committed Apr 15, 2016
2 parents 3a83eb8 + f58885e commit 5ad7168
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 5ad7168

Please sign in to comment.