Given that Laravel's Crypt always adds salt, and so therefore no two instances of the same encryption are the same.
Normally, this is fine because I can compare the decrypted version of the two. However, what if I want to search for a value that is encrypted in the database?
Say that I have a table of users and I would like to encrypt the email address. Now I want to find somebody by the email [email protected].
How do I go about to write the query for this? I cannot just Crypt::encrypt($email) and search since this iteration of the encrypt will be different than the one in the DB.
Edit
Currently, the ONLY thing I can think of is to get all, and filter through them:
$match = User::all()->filter(function($record) use($email) {
$field = $record->email['email'];
if(Crypt::decrypt($field) == $email) return $record;
});
but this is awful. I don't want to search through everything.
keyandiv. I wouldn't be hard to extend the Crypt class to do this.