miladhspr/laravel-encryptable
Composer 安装命令:
composer require miladhspr/laravel-encryptable
包简介
Laravel automatic attribute encryption
README 文档
README
Overview
laravel-encryptable is a package that provides automatic encryption and decryption of model attributes in Laravel applications. This ensures that sensitive data is stored in an encrypted format in the database and is automatically decrypted when accessed within your application.
Features
- Automatic Encryption and Decryption: Automatically encrypts and decrypts specified attributes when interacting with your models.
- Customizable: You can define which attributes should be encrypted using the
$encryptableproperty on the model. - Transparent for Queries: Queries like
where,whereHas,orWhere, etc., work seamlessly with encrypted attributes. - Secure: Data is encrypted using the key defined in your
.envfile, ensuring that only your application can access it.
Installation
1. Install the Package
Run the following command to install the package via Composer:
composer require miladhspr/laravel-encryptable
2. Publish the Configuration (Optional)
You can publish the package's config file with the following command:
php artisan vendor:publish --provider="Miladhspr\LaravelEncryptable\EncryptableServiceProvider"
3. Enable/Disable Encryption
Set ENCRYPTION_ENABLED=true or ENCRYPTION_ENABLED=false in your .env file to enable or disable encryption globally.
4. Define Encrypted Attributes in Your Model
Use the Encryptable trait in your model and specify the $encryptable attribute for fields to be encrypted:
namespace App\Models; use Miladhspr\LaravelEncryptable\Traits\Encryptable; class User extends Model { use Encryptable; protected $encryptable = ['email', 'phone_number']; }
Usage
Inserting/Updating Data
When inserting or updating records, specified attributes in $encryptable are automatically encrypted:
User::create([
'name' => 'John Doe',
'email' => 'john.doe@example.com',
'phone_number' => '1234567890',
]);
miladhspr/laravel-encryptable 适用场景与选型建议
miladhspr/laravel-encryptable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 102 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 miladhspr/laravel-encryptable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 miladhspr/laravel-encryptable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 102
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-22