Skip to content

Commit 5ef74ef

Browse files
author
Hanna
committed
orderByEncrypted function added to EcryptionEloquentBuilder
1 parent 8856e2e commit 5ef74ef

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Builders/EncryptionEloquentBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ public function orWhereEncrypted($param1, $param2, $param3 = null)
3131

3232
return self::orWhereRaw("CONVERT(AES_DECRYPT(FROM_BASE64(`{$filter->field}`), '{$salt}') USING utf8mb4) {$filter->operation} ? ", [$filter->value]);
3333
}
34+
35+
public function orderByEncrypted($column, $direction = 'asc') {
36+
$salt = substr(hash('sha256', config('laravelDatabaseEncryption.encrypt_key')), 0, 16);
37+
return self::orderByRaw("CONVERT(AES_DECRYPT(FROM_bASE64(`{$column}`), '{$salt}') USING utf8mb4) {$direction}");
38+
}
3439
}

0 commit comments

Comments
 (0)