wwardaww / laravel-id-cryption by wwardaww

A trait for Laravel/Lumen Model id encryption.
36
0
2
Package Data
Maintainer Username: wwardaww
Maintainer Contact: aokoruyucu@gmail.com (Ahmet Oğuz Koruyucu)
Package Create Date: 2018-02-06
Package Last Update: 2018-02-06
Language: PHP
License: MIT
Last Refreshed: 2024-11-23 03:20:23
Package Statistics
Total Downloads: 36
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Laravel Id Cryption

Latest Stable Version License

This Trait Encrypt Your Data (from database or somewhere) or, Decrypt Your data (from client or somewhere) and it doesn't effect your real data (from data source).

Based on samwhisker/laravel-trait-encrypt

Installing

composer require wwardaww/laravel-id-cryption

Note : APP_KEY must not be empty in your .env file.

In Your Model File
  • Use Trait :
use Wwardaww\Encryptable;
        
        class YourModel extends Model
        {
        
            use Encryptable; 
  • Add your Encryptable columns and Hidden functions :
 protected $encryptable = [
        'id',
        'account_id',
        'profile_id',
        'user_id',
        'some_id'
 ];
    
 protected $hiddenFunctions = [
        'someDefaultFunc',
        'someDefaultFunc2',  
 ];

Usage

Example Table on Your Data Source

|ID |Name | |---------|---------------| |5 |Ahmet Oğuz |

Get Object Whit Encrypted Id

$encryptedId = "eyJpdiI6IlpxVWtpMGt4dERZbkRcL3hXVTZLKzVRPT0iLCJ2YWx1ZSI6IkhUNzF3MEFsRW1cL2tcLzVTRlZ6QmVaZz09IiwibWFjIjoiZTI5M2JiZTRiNzA2NGVjMTIwNmJhNWZjNjA4YmRmY2NlNzIxYTA2MWM3YTI1ZjVlYzQyMWQ5MzIwZDBlYzQ1OSJ9"
$data = YourModel::decryptFind($encrptedId);

Get Encrypted Data

$data = YourModel::where('somewhere','data')->get()->toArray();
  • Result Will be :
Array(
    [
        "id" => "eyJpdiI6IlpxVWtpMGt4dERZbkRcL3hXVTZLKzVRPT0iLCJ2YWx1ZSI6IkhUNzF3MEFsRW1cL2tcLzVTRlZ6QmVaZz09IiwibWFjIjoiZTI5M2JiZTRiNzA2NGVjMTIwNmJhNWZjNjA4YmRmY2NlNzIxYTA2MWM3YTI1ZjVlYzQyMWQ5MzIwZDBlYzQ1OSJ9",
        "name" => "Ahmet Oğuz"
    ]
)
  • If You don't Convert to Array, Result Will be :
 $data->id = 5,
 $data->name = "Ahmet Oğuz"

Disable Encryption Specific Function

  • You Should Add Your Function to $hiddenFunctions in Your Model File
  • When You Call Your Model in This Function , Result will be :
Call
public function someDefaultFunc2(Request $req){
    $data = YourModel::where('somewhere','data')->get()->toArray();
    ...
}

Result
Array(
    [
        "id" => 5,
        "name" => "Ahmet Oğuz"
    ]
)