Encryption of text data
I'd like to do encryption/decryption of text data in a mutator. Is that going to impact places where I allow filtering and searching? That would depend on how Filament handles search/filter. If it's a normal Eloquent query this might be a no-go. On the other hand, if it's loading data in a way that goes through the mutator I'd be OK. Anyone know?
Solution:Jump to solution
Nope, nope, I take it back. I mixed up local and prod. The end result is as you'd expect. Encryption works but search and sort do not. Bummer.
I'd like to suggest this goes on a roadmap for a feature but I have no idea how it would be done....
8 Replies
That's a good question, I would suspect you will have issues with searching since eloquent will encrypt the data you are passing through it so it will likely only allow exact matches...
Searching/Filtering happens on DB level, so you definitely will have issues.
Somehow, this is working. Searches and sorts are fine and my DB is encrypted.
protected function name(): Attribute
{
return Attribute::make(
get: fn (string $value) => Crypt::decryptString($value),
set: fn (string $value) => Crypt::encryptString($value),
);
}
protected function details(): Attribute
{
return Attribute::make(
get: fn (string $value) => Crypt::decryptString($value),
set: fn (string $value) => Crypt::encryptString($value),
);
}
Interesting 🧐
Solution
Nope, nope, I take it back. I mixed up local and prod. The end result is as you'd expect. Encryption works but search and sort do not. Bummer.
I'd like to suggest this goes on a roadmap for a feature but I have no idea how it would be done.
Yeah, that's the point of encryption right? 😅
I’m so used to clever and useful Laravel features I thought maybe there were some magic way somebody had figured out how to do this. I mean, Agolia can but I’ve never gone down that path. I know this is a difficult problem & there are a handful of solutions. But yeah, not the easy one that I had hoped for. Lol
It's just physically impossible which encrypted data without first decrypting it and then searching. In doing this it would be a massive slow down, I beleive some databases do allow this on the fly, but then the salt would need to be at the database level.