Skip to content

Commit 5ad7168

Browse files
committed
Merge pull request #4 from Dwa1n/master
Extend getOriginal method to decrypt any encrypted fields
2 parents 3a83eb8 + f58885e commit 5ad7168

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/Dtisgodsson/Elocrypt/ElocryptTrait.php

+33
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,37 @@ public function attributesToArray()
167167

168168
return $attributes;
169169
}
170+
171+
/**
172+
* Get the model's original attribute values.
173+
*
174+
* @param string $key
175+
* @param mixed $default
176+
* @return array
177+
*/
178+
public function getOriginal($key = null, $default = null)
179+
{
180+
$original = parent::getOriginal($key, $default);
181+
182+
if(!isset($this->encryptable))
183+
{
184+
return $original;
185+
}
186+
187+
foreach ($this->encryptable as $key)
188+
{
189+
if ( ! isset($original[$key])) continue;
190+
191+
try
192+
{
193+
$original[$key] = Crypt::decrypt($original[$key]);
194+
}
195+
catch(DecryptException $exception)
196+
{
197+
//Do nothing, attribute already exists
198+
}
199+
}
200+
201+
return $original;
202+
}
170203
}

0 commit comments

Comments
 (0)