itskp-odense/vendor/illuminate/database/Eloquent/Casts/AsEncryptedCollection.php

34 lines
960 B
PHP
Raw Normal View History

2021-06-01 08:17:03 +00:00
<?php
namespace Illuminate\Database\Eloquent\Casts;
use Illuminate\Contracts\Database\Eloquent\Castable;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Crypt;
class AsEncryptedCollection implements Castable
{
/**
* Get the caster class to use when casting from / to this cast target.
*
* @param array $arguments
* @return object|string
*/
public static function castUsing(array $arguments)
{
return new class implements CastsAttributes
{
public function get($model, $key, $value, $attributes)
{
return new Collection(json_decode(Crypt::decryptString($attributes[$key]), true));
}
public function set($model, $key, $value, $attributes)
{
return [$key => Crypt::encryptString(json_encode($value))];
}
};
}
}