koel/app/Casts/EncryptedValueCast.php
2024-07-06 17:44:40 +02:00

19 lines
481 B
PHP

<?php
namespace App\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Support\Facades\Crypt;
class EncryptedValueCast implements CastsAttributes
{
public function get($model, string $key, $value, array $attributes): ?string
{
return $value ? Crypt::decrypt($value) : null;
}
public function set($model, string $key, $value, array $attributes): ?string
{
return $value ? Crypt::encrypt($value) : null;
}
}