laravel-database-encryption
laravel-database-encryption copied to clipboard
whereEncryptedIn functionality
As built in functions of laravel like where(), orWhere() clauses, whereIn() clause may also be added into package. Here is some of my dirty way which is working
Function added to file at EncryptionEloquentBuilder class
public function whereEncryptedIn($param1, Array $param2)
{
$filter = new \stdClass();
$filter->field = $param1;
$filter->operation = 'In';
$stringValues = array_map('strval', $param2 );
$valuesWithBrace = json_encode($stringValues);
$singleReplace = str_replace("[","(",$valuesWithBrace);
$filter->values = str_replace("]",")",$singleReplace);
$salt = substr(hash('sha256', env('APP_KEY')), 0, 16);
return self::whereRaw("CONVERT(AES_DECRYPT(FROM_bASE64(`{$filter->field}`), '{$salt}') USING utf8mb4) {$filter->operation}
{$filter->values} ");
`}`
and after that it can be use like whereEncryptedIn()