faustoq / laravel-model-encrypt-fields
加密和解密模型字段
1.0.2
2020-12-03 14:32 UTC
Requires
- php: ^7.3
- illuminate/support: ^7.0 || ^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-06 21:00:20 UTC
README
加密和解密Laravel模型字段
安装
composer require faustoq/laravel-model-encrypt-fields
注意:该包将自动注册,归功于Laravel包自动发现。
发布配置文件
php artisan vendor:publish --provider="ModelEncryptFields\ServiceProvider"
用法
<?php namespace App; use Illuminate\Database\Eloquent\Model; use ModelEncryptFields\EncryptsAttributes; class User extends Model { // Add EncryptAttributes trait use EncryptsAttributes; // List of fields that should be encrypted in your database protected $encrypts = [ 'email', 'name', ]; }
就是这样!现在您可以在模型中自动加密/解密指定在 $encrypts
属性中的字段。
示例
自动加密字段 name
$user->name = "John Doe";
$user->save();
自动解密字段 name
echo "Hello, " . $user->name;