0

I'm working on a project and I want to use encrypt/decrypt for database values. I encrypted the 'email' field, and it works fine, but when I want to run this query I got an error.

The query: Users::where('email', 'example@gmail.com')->get(); -> in this query I want to get a row where the email is example@gmail.com

The error: The data types text and nvarchar are incompatible in the equal to operator. (SQL: select * from [users] where [email] = example@gmail.com)"

I tried to CAST it or CONVERT it, but that doesn't work either. Can someone help me how to run this query?

Here is my model:

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Users extends Model
{
    use HasFactory, Notifiable;
    protected $table = 'users';
    public $timestamps = false;
    protected $fillable = [
        'username',
        'pwd',
        'email'
    ];

    protected $casts = [
        'email' => 'encrypted'
    ];
}

Thanks for your answers!

daniel19
  • 67
  • 8
  • If you're using SQL Server, then https://stackoverflow.com/questions/2726649/the-data-types-text-and-nvarchar-are-incompatible-in-the-equal-to-operator should be helpful – aynber Jan 12 '22 at 18:24
  • So, I have to change the TEXT fields to varchar(max) and that's it? – daniel19 Jan 12 '22 at 18:27
  • @aynber update on the project I changed text to nvarchar(max), but now I'm getting an empty array. – daniel19 Jan 12 '22 at 19:16

0 Answers0