Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In Laravel library, to search encrypted data in MySQL using the LIKE %% operator, we can use the following steps: 1. First, we need to retrieve the encrypted data from the database using the selectRaw method in the query builder. 2. Then, we can use the whereRaw method to apply the LIKE %% operator to the encrypted data. 3. Finally, we can retrieve the search results using the get method.

Example:

$searchTerm = 'keyword'; // the search term entered by user
$encryptedSearchTerm = encrypt($searchTerm); // encrypt the search term

$results = DB::table('mytable')
    ->selectRaw('*, AES_DECRYPT(fieldname, "mysecretkey") as decrypted_fieldname')
    ->whereRaw('AES_DECRYPT(fieldname, "mysecretkey") LIKE ?', ["%{$encryptedSearchTerm}%"])
    ->get();

Note: In this example, we assume that the fieldname column in the mytable table contains the encrypted data, and the encryption key is "mysecretkey".