Skip to content

Commit a0dabb8

Browse files
Merge pull request #21 from luckyhanna/main
orderByEncrypted function added to EcryptionEloquentBuilder
2 parents 8856e2e + 5ef74ef commit a0dabb8

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)