miladhspr/laravel-encryptable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

miladhspr/laravel-encryptable

最新稳定版本:v0.0.4

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 $encryptable property 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 .env file, 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',
]);

统计信息

  • 总下载量: 101
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-22