How can I search data in Laravel using like operator, I have used
encrypt($searchValue);
OR
Crypt::encryptString($searchValue)
But both return full encrypted data but I need searchable data using like operator, In that case, the first name is the encrypted format when is search normal text it returns null
User::where('first_name', 'like', '%' . 'abc' . '%')->get();
//it's return null
When I user
//searchValue is like only 'ab'
User::where('first_name', 'like', '%' . Crypt::encryptString($searchValue) . '%')->get();
//it's also return null
Crypt::encryptString('abc')will output a slightly different string each time you call it. For that reason, you can't do something like:If you're encrypting the string and saving it to the database, the point is that you can't see it as plain-text, and by extension, can't search against it.
Sidenote, your first case
%abc%might return a result, if another encrypted string has that sequence, but it will not be a reliable way to search for the un-encrypted value ofabc, so you can't rely on that.