PHP code example of ajangi / laravel-crypt-model

1. Go to this page and download the library: Download ajangi/laravel-crypt-model 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/ */

    

ajangi / laravel-crypt-model example snippets




use LaravelCryptModel\PrefixedAttributes;

PrefixedAttributes::registerModels([
        'user' => [
            'model' => \App\Models\User::class,
            'attributes' => ['id','avatar_file_id']
        ],
        'Order' => [
            'model' => \App\Models\Oredr::class,
            'attributes' => ['id','customer_user_id']
        ]
    ]);



return [
    'model_new_attribute_prefix' => 'hashed_',
    'aes_secret_key' => env('AES_SECRET_KEY','6818f23eef19d38dad1d272345454549991f6368'), //the secret key you should change
    'aes_secret_iv' => env('AES_SECRET_IV','73658734657823465872364587634876523487657'), //the secret iv you should change
];




namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use LaravelCryptModel\Models\Concerns\HasHashedPrefixedAttributes;

class User extends Model
{
    use HasFactory,Notifiable, HasHashedPrefixedAttributes;
}


use App\Models\User;

$user = User::query()
        ->where('name','Alireza')
        ->first();
return json_encode($user);

use App\Models\User;
$user = User::findByPrefixedAttribute('user_id_hashed_7QOG8YaqVQigyD0sYEd25A=='); // the prefixed hashed value we get in step 4
return json_encode($user);

use LaravelCryptModel\PrefixedAttributes;
$user = PrefixedAttributes::findModel('user_id_hashed_7QOG8YaqVQigyD0sYEd25A=='); // the prefixed hashed value we get in step 4
return json_encode($user);
bash
php artisan vendor:publish --provider="LaravelCryptModel\LaravelCryptoModelServiceProvider"
 config/laravel-crypt-model.php