PHP code example of wwardaww / laravel-id-cryption

1. Go to this page and download the library: Download wwardaww/laravel-id-cryption library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wwardaww / laravel-id-cryption example snippets


use Wwardaww\Encryptable;
        
        class YourModel extends Model
        {
        
            use Encryptable; 
 

 protected $encryptable = [
        'id',
        'account_id',
        'profile_id',
        'user_id',
        'some_id'
 ];
    
 protected $hiddenFunctions = [
        'someDefaultFunc',
        'someDefaultFunc2',  
 ];

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

$data = YourModel::where('somewhere','data')->get()->toArray();

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

 $data->id = 5,
 $data->name = "Ahmet Oğuz"

public function someDefaultFunc2(Request $req){
    $data = YourModel::where('somewhere','data')->get()->toArray();
    ...
}


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