HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/ghayatcom/ghayatcom-api/app/Traits/Encryptable.php
<?php

namespace App\Traits;

trait Encryptable
{
    public function toArray()
    {
        $array = parent::toArray();
        $encryptable = $this->encryptable ?? [];
        foreach ($array as $key => $attribute) {
            if (in_array($key, $encryptable) && $array[$key] != '') {
                try {
                    $array[$key] = decrypt($array[$key]);
                } catch (\Exception $e) {
                    return $value;
                }
            }
        }
        return $array;
    }

    public function getAttribute($key)
    {
        try {
            $value = parent::getAttribute($key);
            $encryptable = $this->encryptable ?? [];
            if (in_array($key, $encryptable) && $value != '') {
                $value = decrypt($value);
                return $value;
            }
            return $value;
        } catch (\Exception $e) {
            return $value;
        }
    }

    public function setAttribute($key, $value)
    {

        $encryptable = $this->encryptable ?? [];
        if (in_array($key, $encryptable)) {
            $value = encrypt($value);
        }
        return parent::setAttribute($key, $value);
    }
}