larapack / attribute-encryption
允许您定义在您的 eloquent 模型中哪些属性应该被加密和解密。
v1.0.0
2015-11-27 10:36 UTC
Requires
This package is auto-updated.
Last update: 2024-09-06 09:09:24 UTC
README
允许您定义在您的 eloquent 模型中哪些属性应该被加密和解密。
安装
使用 Composer 安装 composer require larapack/attribute-encryption 1.*
。
用法
首先将 trait Manipulateable
和 Encryptable
添加到您的 Eloquent 模型中。
<?php
namespace App;
use Larapack/AttributeManipulating/Manipulateable;
use Larapack/AttributeEncryption/Encryptable;
class User
{
use Manipulateable;
use Encryptable;
/**
* @var array List of attribute names which should be encrypted
*/
protected $encrypt = ['password']; // set the attribute names you which to encrypt/decrypt
//...
}
现在每当您设置属性 password
时,它将被加密;当您获取属性时,它将被解密。
测试
$user = new App\User;
$user->password = 'secret';
echo $user->getOriginalAttribute('password'); // Here you will see the encrypted password
dump($user); // Here you will see the encrypted password
echo $user->password; // Here you will see the decrypted password