martinbean/eloquent-encryptable

此包已被废弃且不再维护。未建议替代包。

为 Eloquent 模型添加可加密属性,用于存储敏感数据。

0.3.0 2021-01-20 11:56 UTC

This package is auto-updated.

Last update: 2021-02-20 12:11:52 UTC


README

为 Laravel 6.x 和 7.x 应用程序中的 Eloquent 模型添加可加密属性,用于存储敏感数据。

注意:如果您使用 Laravel 8.x,您不需要此包。Laravel 提供了原生的 encrypted 类型转换,适用于字符串、集合和对象。有关更多信息,请参阅 laravel.com/docs/8.x/eloquent-mutators#attribute-casting

使用方法

只需将特性添加到您的 Eloquent 模型中,并在 $encryptable 属性中定义一个数组,指定要在数据库中加密的属性值

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use MartinBean\Eloquent\Encryptable;

class Patient extends Model
{
    use Encryptable;

    protected $encryptable = [
        'medical_conditions',
        'medical_notes',
        'allergies_and_reactions',
        'medications',
        'blood_type',
        'is_organ_donor',
        'emergency_contact_id',
    ];
}

您可以像通常一样检索这些属性,并且它们将被解密

$medical_conditions = $patient->medical_conditions;

许可证

MIT 许可证下授权。

支持

对于此库的任何问题,请 创建问题