1
0
Fork 0
mirror of https://github.com/archtechx/virtualcolumn.git synced 2025-12-12 23:14:04 +00:00

Handle and test 'encrypted' casts

This commit is contained in:
lukinovec 2023-08-08 09:40:40 +02:00
parent 3213a8e856
commit 874a697d21
2 changed files with 19 additions and 4 deletions

View file

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Stancl\VirtualColumn;
use Illuminate\Support\Facades\Crypt;
/**
* This trait lets you add a "data" column functionality to any Eloquent model.
* It serializes attributes which don't exist as columns on the model's table
@ -31,6 +33,10 @@ trait VirtualColumn
}
foreach ($model->getAttribute(static::getDataColumn()) ?? [] as $key => $value) {
if ($model->hasCast($key, 'encrypted')) {
$value = Crypt::decryptString($value);
}
$model->setAttribute($key, $value);
$model->syncOriginalAttribute($key);
}