kablanfatih / encryption
一个基于配置设置的自动加密和解密 Laravel 中 Eloquent 属性的包。
1.1.0
2020-05-09 14:33 UTC
Requires
- php: >=7.2.0
- ext-json: *
- laravel/framework: ^5.0|^6.0|^7.0
Requires (Dev)
- orchestra/testbench: 4.0
- phpunit/phpunit: ^8.5@dev
This package is auto-updated.
Last update: 2024-09-10 02:10:57 UTC
README
一个基于配置设置的自动加密和解密 Laravel 中 Eloquent 属性的包。
安装
通过 Composer 命令行
composer require kablanfatih/encryption
配置包
只需将 DB_ENCRYPTION_ENABLED 环境变量设置为 true,通过 Laravel 的 .env 文件或托管环境即可。
DB_ENCRYPTION=true
!!! 如果包无法工作 !!!
通过 Artisan 命令行
php artisan config:clear
或 php artisan optimize
用法
在您希望应用加密的任何 Eloquent 模型中使用 Encryptable 特性,并定义一个包含要加密的属性列表的受保护的 $encrypted 数组。
namespace App\Models;
use Encryption\src\Encryptable;
use Illuminate\Database\Eloquent\Model;
class Question extends Model
{
use Encryptable;
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'questions';
/**
* The attributes that are mass assignable.
* @var array
*/
protected $fillable = [
'question', 'incorrect1', 'incorrect2', 'incorrect3', 'incorrect4', 'correct'
];
/**
* The attributes that are encrypted.
*
* @var array
*/
protected $encrypted = [
'question','answer'
];
}