I have a table that one of its column should have encrypted data. I have custom encryption functions in laravel for this purpose. In related model, I use these functions to encrypt and decrypt data while reading or storing in item
column:
public function setItemAttribute($value) {
$this->attributes['item'] = Crypto::EncryptData($value);
}
public function getItemAttribute($value) {
return Crypto::DecryptData($value);
}
By these functions, data is stored as encrypted data in database and is read as decrypted data from database automatically. But the problem appear when I want to use where
clause in my queries (Specially when LIKE
is used.):
$data = Data::select('col1', 'item', 'col2')->where('item', 'LIKE', '%'.$value.'%')->get();
Query with where
clause on col1
or col2
those are not encrypted is fine, but for item
column it has no result.
What should I do for resolving this problem?