waseem/laravel-data-encryption 问题修复 & 功能扩展

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

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

waseem/laravel-data-encryption

最新稳定版本:1.0.1

Composer 安装命令:

composer require waseem/laravel-data-encryption

包简介

Automatically encryption and decryption data overriding by using getAttribute an setAttribute methods of Eloquent Model.

README 文档

README

A trait to encrypt data models in Laravel, this automatically encrypt and decrypt model data overriding getAttribute an setAttribute methods of Eloquent Model.

How to install

Run composer installation

    composer require waseem/laravel-data-encryption

Add ServiceProvider to your app/config.php file

    'providers' => [
        ...
        \Waseem\Encipher\EncipherServiceProvider::class,
    ],

Publish configuration file, this will create config/encrypt.php

     php artisan vendor:publish --provider=Waseem\Encipher\EncipherServiceProvider

How to use

  1. You must add SECRET_ENCRYPT_KEY and ENCRYPT_PREFIX in your .env file or set it in your config/encrypt.php file

  2. Use the Waseem\Encipher\Encipher trait:

    use Waseem\Encipher\Encipher;
  3. Set the $encipher array on your Model.

    protected $encipher = ['encrypted_property'];
  4. Here's a complete example:

    <?php
    
    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    use Waseem\Encipher\Encipher;
    
    class User extends Model
    {
    
        use Encipher;
    
        /**
         * The attributes that should be encrypted when stored.
         *
         * @var array
         */
        protected $encipher = [ 'email', 'name' , 'mobile'];
     
        /**
        * Optionally you can define the attributes that should be converted to camelcase when retrieve.
        *
        * @var array
        */
         protected $camelcase = ['name'];
    }
  5. Optional. Encryption your current data

    if your lavarel application version 5.8+

    If you have current data in your database you can encrypt it with the: php artisan encipher:encryptionModel 'App\Models\User' command.

    Additionally you can decrypt it using the:php artisan encipher:decryptionModel 'App\Models\User' command.

    Note: You must implement first the Encipher trait and set $encipher attributes

  6. If you are using exists and unique rules with encrypted values replace it with exists_encrypted and unique_encrypted

    $validator = validator(['email'=>'wasi@demo.com'], ['email'=>'exists_encrypted:users,email']);

    OR

    $rules=array(
        'email' => 'required|unique_encrypted:users,email'
    );
    $messages=array(
        "email.unique_encrypted"=>"The email has already been taken."
    );
  7. You can still use where functions

    $validator = User::where('email','wasi@demo.com')->first();

    Automatically wasi@demo.com will be encrypted and pass it to the query builder.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固